Python Uses in Such O/S:-
--------------------------
- UNIX
- Mac O/S
- Wiindows
First Program:-
----------------
- print("Abhsihek Pathak is a IT Trainer.")
Abhsihek Pathak is a IT Trainer.
- print("Abhsihek Pathak is a IT Trainer.")
- 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
- 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
- print(100)
- print(200)
100
200
- print(100)
- 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
- print(name)
- print(age)
- print(price)
- 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:-
------------------------
- 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.
- An identifiers can not start with digit. So while variable1 is valid, 1variable is not valid.
- We can not use special symbols like !,#,@,%,$ etc in our identifier.
- Identifier can be of any length.
Data Type in Python:-
----------------------
There are two types of data type in python.
- Mutable Data Type
- Immutable Data Type
"Mutable object can change its state or contents and immutable objects cannot."
Mutable Data Type:-
-------------------
- List
- Dictionary
- byte array
----------------------
- Int (+ve,-ve,0)
- Float (100.50)
- Complex
- String ("Abhishek Pathak")
- Tuple
- set
- None (a = )
- Boolean (True or False)
Note:- "Three types of number used in python data type."
- Integer
- Float
- 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
- print(type(name))
- print(type(age))
- 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'''
- name="Abhishek Pathak"
- print(name,type(name))
Abhishek Pathak <class 'str'>
- name = '''
- Today is Sunday
- Tomorrow is Monday
- '''
- 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']
- l=[10,'Abhsihek',100.50]
- print(l,type(l))
Note:- "Index Number"
- l=[10,'Abhsihek',100.50]
- l[2]=200
- 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)
- l=(10,'Abhsihek',100.50)
- print(l,type(l))
(10, 'Abhsihek', 100.5) <class 'tuple'>
- l=(10,'Abhsihek',100.50)
- l[2]=200
- 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:
- Single line comments #
- 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.
- Arithmetic Operators(+,-,*,/,%,**)
- Relational/Comparison Operators(==,!=,>=,<=,<,>)
- Assignment Operators(=,+=,-=,*=,/=,%=,**=)
- 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