Introduction to Python

 






Python Uses in Such O/S:-
--------------------------
  1. UNIX
  2. Mac O/S
  3. Wiindows

First Program:-
----------------
  1. print("Abhsihek Pathak is a IT Trainer.")
Abhsihek Pathak is a IT Trainer.

  1. print("Abhsihek Pathak is a IT Trainer.")
  2. print("Success path of data transmission between two or more nodes that is known as comunication")
Abhsihek Pathak is a IT Trainer.
Success path of data transmission between two or more nodes that is known as comunication

  1. print("Abhsihek Pathak is a IT Trainer.,Success path of data transmission between two or more nodes that is known as comunication")
Abhsihek Pathak is a IT Trainer.Success path of data transmission between two or more nodes that is known as comunication

  1. print(100)
  2. print(200)
100
200

  1. print(100)
  2. print(200+100)
100
300

Variables: A variable is a name given to a memory location in a program. When we type a variable in python thereafter python print the value infront of my screen.

name = "Abhishek Pathak"
age = 32
price = 100.50
weight = 32

  1. print(name)
  2. print(age)
  3. print(price)
  4. print(id(name),id(age),id(weight))
Abhishek Pathak
32
100.5
1699679173040 140725619517320 140725619517320

Note:- "name is a variable & Abhishek Pathak is a value." Always use Simple,Short & Meaningful variable by the good programer.

Rules for Identifiers:-
------------------------
  1. Identifiers can be combination of uppercase and lowercase letters,digits or an underscore(_). So myVariable, variable_1, variable_for_print all are valid python identifiers.
  2. An identifiers can not start with digit. So while variable1 is valid, 1variable is not valid.
  3. We can not use special symbols like !,#,@,%,$ etc in our identifier.
  4. Identifier can be of any length.

Data Type in Python:-
----------------------
There are two types of data type in python.
  1. Mutable Data Type
  2. Immutable Data Type
"Mutable object can change its state or contents and immutable objects cannot."

Mutable Data Type:-
-------------------
  1. List
  2. Dictionary
  3. byte array
Immutable Data Type:-
----------------------
  1. Int  (+ve,-ve,0)
  2. Float (100.50)
  3. Complex
  4. String ("Abhishek Pathak")
  5. Tuple
  6. set
  7. None (a = )
  8. Boolean (True or False)

Note:- "Three types of number used in python data type."
  1. Integer
  2. Float
  3. Complex
a = 10
print(a,"is of type",type(a))
#5 is of type <class 'int'>

b = 100.50
print(b,"is of type",type(b))
#100.50 is of type <class 'float'>

c = 1+2j
print(c,"is of type",type(c))
#5 is of type <class 'complex'>


name = "Abhishek Pathak"
age = 32
price = 100.50
weight = 32
  1. print(type(name))
  2. print(type(age))
  3. print(type(price))
<class 'str'>
<class 'int'>
<class 'float'>

A string is a collection of one or more characters put in aa single quote,double-quote or triple quote. Multi-line strings can be denoted using triple quotes, '''or'''
  1. name="Abhishek Pathak"
  2. print(name,type(name))
Abhishek Pathak <class 'str'>

  1. name = '''
  2. Today is Sunday
  3. Tomorrow is Monday
  4. '''
  5. print(name,type(name))
Today is Sunday   
Tomorrow is Monday
 <class 'str'>

List is an ordered sequence of items. It is one of the most used datatype in Python and is very flexible. Always use in []. Mostly used data type in python. We can add multiple elements in list with comma.

a = [1,2.2,'ws']

  1. l=[10,'Abhsihek',100.50]
  2. print(l,type(l))
[10, 'Abhsihek', 100.5] <class 'list'>

Note:- "Index Number"

  1. l=[10,'Abhsihek',100.50]
  2. l[2]=200
  3. print(l,type(l))
[10, 'Abhsihek', 200] <class 'list'>

Tuple is an ordered sequence of items same as a list. It is defined within parentheses () where items are separated by commas. It's fast comare to list. Multiple value use in tuple.
t = (5,'program',1+3j)

  1. l=(10,'Abhsihek',100.50)
  2. print(l,type(l))
(10, 'Abhsihek', 100.5) <class 'tuple'>


  1. l=(10,'Abhsihek',100.50)
  2. l[2]=200
  3. print(l,type(l))
l(2)=200
    ^^^^
SyntaxError: cannot assign to function call here. Maybe you meant '==' instead of '='?


Set:- A set is an unordered collection of items. Every set elements is unique(no duplicates) and must be immutable(can not be changed). Always use curly breaket{}.
set = {10,100,200,10}
print(set,type(set))
{200, 10, 100} <class 'set'>

Keywords are the reserved words whose meaning already defined in the python interpreter.
1) We can not use a keyword as a variable name, method name or any other identifier.
2) Python keywords are the case sensitive.
Total 35 keywords 

import keyword
keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async', 'await', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'nonlocal', 'not', 'or', 'pass', 'raise', 'return', 'try', 'while', 'with', 'yield']

Print Sum:-
-----------
a=100
b=200
sum=a+b
print(sum)
300


Print Diff:-
------------
a=100
b=200
diff=a-b
print(diff)
-100


Python Comments:-
Comments are nothing but ignorable part of python program that are ignored by the interpreter. It enhance the readability of codes.
There are 2 types of comments:
  1. Single line comments #
  2. Multi line comments """______""""
name = "Abhishek Pathak" #This is a string data type.
print(name)
Abhishek Pathak

Operator is a nothing but symbols that perform certain task.
  1. Arithmetic Operators(+,-,*,/,%,**)
  2. Relational/Comparison Operators(==,!=,>=,<=,<,>)
  3. Assignment Operators(=,+=,-=,*=,/=,%=,**=)
  4. Logical Operators(not,and,or)
Arithmetic Operators:-
----------------------
a=100
b=10
print(a+b) #110
print(a-b) #90
print(a*b) #1000
print(a**b) #100000000000000000000
print(a/b) #10.0
print(a//b) #10

110
90
1000
100000000000000000000
10.0
10

Relational Operators:-
----------------------
a=14
b=4
print(a<b) #False
print(a>b) #True
print(a==b) #False
print(a!=b) #True
print(a<=b) #False
print(a>=b) #True

False
True
False
True
False
True

Logical Operator:-
------------------
a=14
b=4
print(a<b and a>b) #False  (If both statement is true then display   
                            true)
print(a<b or a>b) #True     (If one statement is true then display  
                            true)
print(not(a<b and a>b)) #True  (Change the statement)

False
True
True

No comments:

Post a Comment

Pseudocode + Python Programing

Introduction to Python Introduction to Flowchart & Pseudocodes