Python
Why python
- open source
- interpreted language- execute the program line by line at the runtime rather than beging pre compiled in to machine code.
- symple synthetical construction- easy to read and comprehend
- provides thousands of 3rd party module.
Structure of the program
#shebang line #! /usr/bin/python
import statements
import <module>
gather the code in main function
def main():
print (“Hello world”);
standard boiler plate to call main function
if __name__ == “__main__”:
in python intend(space) is important for structure of the program.
Variables
no need to declare data types
must start with letter or underscore
cannot start with special characters except underscore
datatype will be assigned based the latest value assigned to the variable
a = “Arun”
b=1.52
print(type(x))
this will provide the type of the variable.
datatypes
string in “”” arunram
python””” — -multi line comments.
print f string
instead of using comma , in print statement f string command is used to display the runtime values in python
print(f”my name is {name} my age is {age}”)
type casting in python
to convert one data type to another
implicit type casting and explicit type casting
implicit:
x = 10
y=11.5
z=x+y
type(z) = i = float
here integer 5 will be implicitly converted to flot before addition
Get Arunram’s stories in your inbox
Join Medium for free to get updates from this writer.
explicit conversion:
x = 5
y = float(x)
z= x+y
here y is explicitly converted to float.
Arithmetical operation
- +,-,*,/,//,%,**
- addition,subtraction,division,multiplication,floor division,module,exponential.
- // floor division operator provides the reminder with lower round of value.
- % provides the remainder
- ** provides exponential value
comparision operators
==,!=,>,<, ≥,≤
logical operators
returns true or false
and, or , not
x = True
y = False
print(“x not y”, not x)
assignment operators
==,c+=2,c-=2
Data structures in python
LIST:[]
List_set = [1,2,3,4,5,5,4,3]
(mutable, maintains the same input order(ordered), allows duplicates,allow multiple nulls)
SET:{}
set_data = {1,2,3,4,5}
(mutable ,default in asd order(unordered), doesn’t allow the duplicates, allow only one null)
TUPLE:()
tuple = (1,2,3,4)
(unmutable , same in input order(ordered), allows duplicates,allows multiple null)
dictionary:{}
key value pair
dict_set=
{
key:value,
“name” :”Arunram”,
“age” : 23
}
(muted,ordered,allows duplicate for only values not for keys, only one null in key, multiple null in value)




