Learn python in short time

 


 In this tutorial we are going to so you how to  learn python programming language in short time very easy and quick, so lets get started ............


What is Python?

Python is one of the most popular, general-purpose, interpreted, object-oriented high-level programming languages. It was created by "Guido van Rossum" and published in 1991.

It is used to:

  • Web Development (Server Side),
  • Drone Development,
  • Mathematics,
  • System Scripting.
  • Data science
  • Artificial intelligence (AI)
  • Machine learning (ML)
  • Robotics and more.

What  can we do with Python?

  • Python can be used to create web applications.
  • Python can be used in software to create workflows.
  • Python can connect to database systems. and It can also modify and read the files.
  • Python can be used to process big data and perform complex mathematics.
  • Python can be used for rapid prototyping or production-ready software development.

Why Python?

  • Python runs on a variety of platforms (Windows, Mac, Linux, Raspberry Pi, etc.).
  • Python has a simple syntax similar to English.
  • Python has syntax that allows developers to write programs in fewer lines than other programming languages.
  • Python runs on an interpreter system. This means that as soon as you write your code, you can run it. This means prototyping can be very fast.

Python Syntax

  • Developed for readability, Python has some similarities to English and is influenced by mathematics.
  • Python uses newlines to complete commands, unlike other programming languages ​​that often use semicolons and parentheses.
  • Python relies on indentation with spaces to define scope. Similar to loop, function, and class scoping. Other programming languages ​​often use curly braces for this purpose.
>>print("Hello, World!")

Output 

>>Hello, world!

Python Comments

  • You can use comments to describe Python code.
  • You can use comments to make your code easier to read.
  • Comments can be used to prevent execution when testing code.
  • Comments starting with # are ignored by Python:

Example: 

#print string hello world this line will be ignore by python.
print("Hello, World!")

Output 

>>Hello, world!

Multiline Comments

  • Python has multiline comment syntax, which can be used ''' '''(triple quade).
  • To add a multi-line comment, you can insert # on each line.

Variables

  • Variable is an one type of container which is it stored the data value in memory location.
  • A variable is created the moment you first assign it a value.

Example:

x = 4       # x is of type int

y = "Sally" # x is now of type str

print(y)

Output:

Sally

Casting

If you want to specify the data type of a variable, This can be done with a cast.

x = str(3)    # x will be '3'
y = int(3)    # y will be 3
z = float(3)  # z will be 3.0

Type:

You can get the data type variable with type() function.

Example:

x = 5
y = "John"# Declaring Variables
print(type(x))
print(type(y))# this will print data type of variable

Note: Variables are case sensitive

Assign Multiple Values

In Python, you can assign values ​​to multiple variables in one line.

Example

x, y, z = "mango""orange""banana"
print(x)
print(y)
print(z)

Unpack a Collection

If you have a collection of values ​​in lists, tuples, etc., you can use Python to extract the values ​​into variables. It's called unpacking.

Example

fruits = ["mango""orange""banana"]
x, y, z = fruits
print(x)
print(y)
print(z)

Output Variable

The Python function print() is often used to print variables.
example

x = "Python is great"
print(x)

Output

Python is great


The print() function prints multiple variables separated by commas:

Example

x = "Python"
y = "is"
z = "great"
print(x, y, z)

You can also use the + operator to print multiple variables:

Example

x = "Python "
y = "is"
z = "great"
print(x + y + z)

Global Variable

Variables created outside a function (as in all the examples above) are called global variables. Global variables are available to everyone, inside or outside the function.

Example

x = "great"# Creating a global variable

def myfunc():
  print("Python is " + x)

myfunc()# This will print whatever is inside the function plus global variable.

Python Data Types
Data types are an important concept in programming. Variables can store different types of data, and different types can do different things.
Python has the following data types built into these categories by default:

Example


Python Numbers
Python has three number data types:

·         int

·         float

·         complex

Numeric variables are created by assigning a value:

example:

x = 1    # int
y = 2.8  # float
z = 1j   # complex


Python numeric types

Integer:

An Int or Integer is a positive or negative integer with no fractional part and unlimited length.

Example

x = 1
y = 35656222554887711
z = -3255522

float:


A float or "floating point number" is a positive or negative number with one or more decimal places.

Example

x = 1.10
y = 1.0
z = -35.59

A float can also be a scientific number with an "e" to indicate powers of ten.

Complex

Complex numbers are written with a "j" as the imaginary part:

Example

x = 3+5j
y = 5j
z = -5j

Type Conversion

You can convert from one type to another with the int()float(), and complex() methods:

Example

x = 1    # int
y = 2.8  # float
z = 1j   # complex

#convert from int to float:
a = float(x)

#convert from float to int:
b = int(y)

#convert from int to complex:
c = complex(x)

Random Numbers
Python does not have a random()  function to create random numbers, but Python has a built-in module called random  that can be used to create random numbers.

Example:

import random # import random variables

print(random.randrange(110)) # Which is range between 1 and 9

Python Casting

Sometimes you want to specify the type of a variable. This can be done by pouring. Since Python is an object-oriented language, classes are used to define data types, including primitive types.

Casting in Python is therefore done using the constructor function:
 int()   an integer literal, a float literal (with all digits after the decimal point removed), or a string literal (a string is (assuming it represents an integer). 

• float()  - constructs a floating point number from an integer literal, floating point literal, or string literal (assuming the string represents a floating point number or an integer).

• str()  - many including Constructs strings from data types of strings, integer literals, floating point literals

Example                                                     

x = int(1)   # x will be 1
y = int(2.8# y will be 2
z = int("3"# z will be 3

x = float(1)     # x will be 1.0
y = float(2.8)   # y will be 2.8
z = float("3")   # z will be 3.0
w = float("4.2"# w will be 4.2

Python Booleans

When programming, it is often necessary to know whether an expression is True or False. You can evaluate any expression in Python to get one of two answers: True or False.
When comparing two values, an expression is evaluated and Python returns a boolean answer.

Example

print(10 > 9# This will print boolean answer true
print(10 == 9# This will print boolean answer false
print(10 < 9# This will print boolean answer false

The bool() function allows you to evaluate any value, and give you True or False in return.

Example

x = "Hello"
y = 15
print(bool(x))
print(bool(y))

Most values ​​are true
• Almost all values ​​evaluate to True if they contain some content.
• All strings are True except the empty string.
• All numbers except are True .
• All lists, tuples, sets and dictionaries are True except empty ones.

Example

bool("abc")
bool(123)
bool(["apple""cherry""banana"])

Some values ​​are false

In fact, not many values ​​evaluate to false except for empty values ​​such as ()[]{}"" the number 0, and the value None. Of course, 
the value False evaluates to False.
Python also has many built-in functions that return boolean values, such as the isinstance()  function that can be used to determine if an object is of a particular data type.




0 Comments