0% found this document useful (0 votes)
15 views12 pages

Programming in Python Language

The document provides an overview of programming in Python, detailing the types of programming languages, including low-level and high-level languages. It explains the role of translators like compilers and interpreters, and introduces Python as an interpreted, high-level, object-oriented language with various features and data types. Additionally, it covers variable naming rules, keywords, constants, escape sequences, and operators in Python.

Uploaded by

ahmadnadeem27850
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views12 pages

Programming in Python Language

The document provides an overview of programming in Python, detailing the types of programming languages, including low-level and high-level languages. It explains the role of translators like compilers and interpreters, and introduces Python as an interpreted, high-level, object-oriented language with various features and data types. Additionally, it covers variable naming rules, keywords, constants, escape sequences, and operators in Python.

Uploaded by

ahmadnadeem27850
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Programming in Python Language

Programming:
A program is the set of instructions to be executed by the computer to
accomplish a particular task. Programming is an art . It performing a computational
task and converts these tasks into machine readable form.
प्रोग्राभ किसी विशेष िामय िो ऩूया ियने िे लरए िंप्मूटय द्वाया लनष्ऩाकदत किए
जाने िारे लनदे शों िा सभूह है । प्रोग्रालभंग एि िरा है । मह िामय
dks iwjk ियता है औय इन िामों िो भशीन ds ऩठनीम रूऩ भें ऩरयिलतयत ियता है ।
Language: Language are two types-
1. Low Level language
2. High Level Language

Low Level Language: These are two Types-


1. Machine Language- Binary Form- 0 and 1
1St Generation
2. Assembly Language- 2nd Generation
Mnemonics Code- add ,sub
Translator- Assembler
High Level Language: Third Generation
C,C++, Java, Python, .Net , Pascal, Fortran, Basic, COBOL etc.
Translator- Compiler and Interpreter
Source Code-
Object Code-

-: Translators :-
-: Compiler :-
A program which translates high level language program into a machine
language is called compiler. It checks all kind of limits, range, errors etc. But its
program execution time is more and occupies a larger part of the memory. It has
low speed and low efficiency of memory utilization. It converts all source code into
machine (object) code at one time.
एि प्रोग्राभ जो gkbZysaoy ySXost प्रोग्राभ िो भशीन बाषा भें अनुिाद ियता है उसे
िंऩाइरय िहा जाता है । मह सबी प्रिाय िी सीभाओं, यें ज, त्रुकटमों आकद िी जांच
ियता है , रेकिन इसिा प्रोग्राभ लनष्ऩादन सभम अलधि है औय भेभोयी िे एि फडे
कहस्से ऩय िब्जा िय रेता है । इसभें भेभोयी उऩमोग िी गलत िभ औय दऺता िभ
gksrh है । मह एि सभम भें सबी lkslZ िोड िो भशीन िोड (ऑब्जेक्ट िोड) भें
ऩरयिलतयत ियता है ।
-: Interpreter :-
An interpreter is a program which translates one statement of a high-level
language program into machine codes and executes it. An interpreter is a smaller
program as compared to the compiler. It needs less memory space. It can be used in
a smaller system which has limited memory space. Interpreter convert source code
into machine code sentence by sentence.
bUVjizsVj एि प्रोग्राभ है जो gkbZyosa y ySXost izksxzke िे एि स्टे टभेंट िो भशीन िोड भें
cnyrk है औय इसे लनष्ऩाकदत ियता है । िंऩाइरय िी तुरना भें bUVjizsVj एि छोटा
प्रोग्राभ है । इसे भेभोयी स्ऩेस िभ चाकहए। इसिा उऩमोग एि छोटे लसस्टभ भें
किमा जा सिता है जजसभें भेभोयी स्ऩेस सीलभत है । bUVjizsVj lkslZ िोड िो भशीन
िोड esa ,d&,d LVsVesUV esa ऩरयिलतयत ियता है ।
-: Assembler :-
A program which translates an assembly language program into a machine
language program is called an assembler.
एि प्रोग्राभ जो असेंफरी रैंग्िेज प्रोग्राभ िो भशीन रैंग्िेज प्रोग्राभ भें cnyrk है , उसे
असेम्फरय िहा जाता है ।
Python
Python is an interpreted, high Level, general purpose programming
language . It is developed by Guido van Rossum and first released in 1991.
It is an object oriented programming language. In python we can easily
create and use classes and objects. Python is the case sensitive language.
ऩामथन एि baVjizsfVM] gkbZyosa y, साभान्म प्रमोजन प्रोग्रालभंग बाषा है । मह Guido
van Rossum द्वाया वििलसत किमा गमा है औय ऩहरी फाय 1991 भें जायी किमा
गमा था। मह एि vkCtsDV vksfj,fUVM प्रोग्रालभंग बाषा है । ऩामथन भें हभ Dykl औय
vkCtsDVl िो आसानी से फना औय उऩमोग िय सिते हैं । ऩामथन dsl lsUlhfVo बाषा
है ।
Features of Python
 It is Easy to use.
 It is portable Language
 Interpreted language
 Free and open source
 Objected oriented language
 GUI (Graphical User Interface) Programming
 Easy Integration with other apps
 मह प्रमोग ियने भें आसान है ।
• मह ऩोटे फर बाषा है
• baVjizsfVM बाषा है
• Qzh औय vksiu lkslZ gS
• vkCtsDV vksfj,fUVM प्रोग्रालभंग बाषा है
• जीमूआई (ग्राकपिर मूजय इं टयपेस) प्रोग्रालभंग
• अन्म एजप्रिेशन िे साथ आसान एिीियण
Version in Python
Python Released 1991
Python 1.0 1994
Python 2.0 2000
Python 3.0 2008
Python 2.7 2010
Python 3.7 2018
Python 3.8 13 May 2020
Python 3.9 5 October 2020
Current Latest Version 3.12.0

Data Types
int : Integer Numbers&[Link] la[;k Ex- 3, 426
float : n”keyo okyh la[;k Ex- 4.5, 24.645
char : Alphabetic character: „A‟ to „Z‟
Numeric Character: „0‟ to „9‟
special char-„$‟ , „#‟ and other symbol.
In python No char data type.
string(str) : Set of Character
Ex -“Mohan”, “Thakurdwara”
Variables/ Identifier in Python
Variable is the name of the memory space . A variable is a name which is used to
refer memory location and used to hold value do not need to be declared with any
particular data type and can even change data type after they have been set. You can
change the value of variable.
oSfj;oy eSeksjh esa स्थान िा नाभ हैं । िैरयएफर एि ऐसा नाभ है , जजसिा उऩमोग
भेभोयी रोिेशन िो संदलबयत ियने िे लरए किमा जाता है औय िैल्मू िो होल्ड
ियने िे लरए उऩमोग किमा जाता है , किसी विशेष MsVk टाइऩ िे साथ घोवषत ियने
िी आिश्मिता नहीं होती है औय िे सेट होने िे फाद बी MsVk टाइऩ फदर सिते हैं ।
vki oSfj;oy dh cSY;w cny ldrs gSaA
x=4 # Here x is of int type
x=”Mohan” # Here x is now of string type
x=3.56 # here x is now of float type

-: Rules of Constructing Variable Name :-


1. A variable name is a combination of any Alphabets, Digits and Underscore ( _
).
2. The first character in the variable name must be an alphabet.
3. No commas or blanks are allowed with in a variable name.
4. No special symbol other than an underscore can be used in a variable name.
5. You cannot use keyword as a variable name.
- oSfj;oy नाम के ननमााण के ननयम: -
1. एि oSfj;oy नाभ किसी बी अऺय, अंि औय अंडयस्िोय (_) िा एि संमोजन
है ।
2. oSfj;oy नाभ िा ऩहरा िणय एि djsDVj होना चाकहए।
3. oSfj;oy नाभ िे साथ िोई अल्ऩवियाभ मा रयक्तता िी अनुभलत नहीं है ।
4. अंडयस्िोय िे अरािा िोई विशेष प्रतीि oSfj;oy नाभ भें उऩमोग नहीं किमा
जा सिता है ।
5. आऩ oSfj;oy नाभ िे रूऩ भें िीिडय िा उऩमोग नहीं िय सिते।
Keywords
Keywords are those words whose meaning is already defined to the compiler.
They are also called reserve words. You cannot use keyword as a variable
name. There are 33 keywords in Python language.
Example :-and, or ,not , if, else, for, while, True , False, None, return, in, from,
break, continue etc.
कीवर्ा वे शब्द हैं जिनके अथा पहऱे से ही कंपाइऱर के नऱए पररभाषषत हैं । आप
एक oSfj;oy नाम के रूप में कीवर्ा का उपयोग नहीं कर सकते। उन्हें आरजऺत शब्द
भी कहा िाता है । पायथन भाषा में 33 कीवर्ा हैं ।
Example :-and, or ,not , if, else, for, while, True , False, None, return, in, from,
break, continue vkfnA

-: Constant :-
A constant is the fixed value of any type. You cannot change the value of the
constant.
Ex- a=5, b=10
constant किसी बी प्रिाय िा लनजित िैल्मू है । आऩ constant िा भान नहीं
फदर सिते।
-: Escape Sequence :-
Escape sequence are use to screen formatting. They always start with
back slash ( \ ).
Escape sequence स्रीन स्िरूऩण िे लरए उऩमोग किमा जाता है । िे हभेशा फैि
स्रैश (\) से शुरू gksrs हैं ।
Escape Sequence Use
1. \n :- New line.
2. \t :- Tab key.
3. \v :- Vertical tab.
4. \a :- Beep key.
5. \’ :- Single quote.
6. \” :- Double quotes.
7. \? :- Question mark.
8. \0 :- Null character.

-: Data Type in C :-
Data type Size(Byte) Range Format Specifier
int or signed int /short int 2 -32768 to 32767 %d or %i
unsigned int 2 0 to 65535 %u
long int 4 -2147483648 to 2147483647 %ld
unsigned long int 4 0 to 4294967295 %lu
char 1 -128 to 127 %c
unsigned char 1 0 to 255 %c
float 4 -3.4*10-38 to 3.4*1038 %f
double 8 -1.7*10-308 to 1.7*10308 %lf
long double 10 -3.4*10-4932 to 1.1*104932 %lf
string %s
Python Numbers
There are three Numeric Types in Python:
ऩामथन भें तीन ;wefs jd Vkbi Vkbi हैं
 int
 float
 complex
Variable of numeric types are created when you assign a value of them.
जफ आऩ ;wefs jd Vkbi oSfj;oy भें िोई भान असाइन ियते हैं तो U;wesfjd Vkbi िा
ऩरयितयन होता है ।
x=1 # int
y=2.8 # float
z=1j # complex
Python type Casting
Integers:
x=int(1) # x will be 1
y=int(2.8) # y will be 2
z=int(“3”) # z will be 3
Float:
x=float(1) # x will be 1.0
y=float(2.8) # y will be 2.8
z=float(“4.2”) # z will be 4.2
String:
x=str(“s1”) # x will be „s1‟
y=str(2) # y will be „2‟
z=str(3.0) # z will be „3.0‟
-: Operators :-
An operator specifies an operation which can be perform on operands. There
are many types of operators.
एक ऑपरे टर एक ऑपरे शन को ननर्दा ष्ट करता है िो ऑपरें र् पर र्कया िा सकता
है । कई प्रकार के ऑपरे टर हैं ।
1. Arithmetical operators
2. Relational operators or comparison operator
3. Logical operators
4. Bitwise operators
5. Assignment Operator
6. Membership Operator
7. Identity Operator
-: Arithmetical Operators :-
Arithmetical operators are two types.
1. Binary operators
2. Unary operators
-: Binary Operators :-
Binary operators performed on two operands. They are performed left to
right.
Example: +, -, *, /, %
फाइनयी ऑऩये टय दो ऑऩयें ड ऩय प्रदशयन ियते हैं । िे फाएं से दाएं प्रदशयन ियते हैं ।
Ex-
+ Addition,
- subtraction
* Multiplication
/ Division
% Modulation
// Floor Division
** Exponent-power
-: Unary Operators :-
Unary operators performed on one operand. They are perform right to left.
मूलनमयी ऑऩये टय एि ऑऩयें ड ऩय प्रदशयन ियते हैं । िे दाएं से फाएं प्रदशयन ियते हैं ।
Example : Unary Positive (+), Unary Negation(-)
: Expression :-
An expression is the combination of operators and variables or values which
combined together to produce a new Value.
इक्स्प्रेशन ऑऩये टयों औय oSfj;oy मा oSY;w िा संमोजन है जो एि साथ लभरिय एि
नमा oSY;w cukrs हैं ।

Example:
5*3-6/2+5
15-3+5
12+5=17
-: Relational Operators :-
Relational operators are use to check the relation between two expression.
रयरेशनर ऑऩये टय िा उऩमोग दो इक्स्प्रेशन िे फीच संफंध िी जांच ियने िे लरए
किमा जाता है ।
> :- Grater than.
< :- less than.
== :- equal to.
>= :- greater than equal to.
<= :- less than equal to.
!= :- not equal to.
-: Logical Operators :-
Logical operators are used to compare the results of two or more expressions.
दो मा अलधि इक्स्प्रेशन िे ऩरयणाभों िी तुरना ियने िे लरए रॉजजिर ऑऩये टसय
िा उऩमोग किमा जाता है ।
1. and (&&)
2. or (||)
3. not (!)
AND *
Input Output
A B C
0 0 0
0 1 0
1 0 0
1 1 1
0 False
1 True
OR +
Input Output
A B C
0 0 0
0 1 1
1 0 1
1 1 1
NOT Reverse
INPUT OUTPUT
0 1
1 0

3-: Bitwise Operators :-


Bitwise operator works on memory bits.
षिटवाइज़ ऑपरे टर मेमोरी षिट्स पर काम करता है ।
1. >> :- right shift operator
2. << :- left shift operator.
3. & :- bitwise AND operator.
4. | :- bitwise OR operator.
5. ^ :- bitwise XOR operator.
6. ~ :- one‟s Compliment operator
Bits – 0 and 1
Binary base =2

1. Bitwise AND operator(&) - if both bits are 1 then result 1 otherwise


result will be 0.
मकद दोनों वफट्स 1 हैं तो ऩरयणाभ 1 होगा अन्मथा ऩरयणाभ 0 होगा।

5&6
101
110
100
2. Bitwise OR Operator(|)- if at least bit is 1 then result 1 otherwise
result will be 0.
मकद िभ से िभ वफट 1 है तो ऩरयणाभ 1 है अन्मथा ऩरयणाभ 0 होगा।
5|6
101
110
111
3. XOR Operator (^)-
If both bits are different then result 1 otherwise Result will be 0.
मकद दोनों वफट अरग-अरग हैं तो ऩरयणाभ 1 नहीं तो ऩरयणाभ 0 होगा।
1100
0101
1001

4. ~ One’s Complement Operator (Bitwise NOT operator)


if input is 0 then result 1 , if input 1 then result will be 0
मकद इनऩुट 0 है तो ऩरयणाभ 1, मकद इनऩुट 1 है तो ऩरयणाभ 0 होगा
101=010
-: Assignment Operators :-
These are used to assign the value in the variable.
इनिा इस्तेभार िैरयएफर भें िैल्मू असाइन ियने िे लरए किमा जाता है ।

Example :- =, +=, -=
Example :- a=b=c=d=10.
a=5 b=25

a+=1
a=a+1

a-=1
a=a-1

Membership operators
The membership operators are useful to test for membership in sequence such as
string, lists , tuples and dictionaries.
esEcjfli vkijsVlZ रभ भें esEcjfli tkWp djus िे लरए उऩमोगी होते हैं जैसे जस्रं ग,
fyLV, ट्मूऩल्स औय fMD”kujh।
There are two types of membership operator.
esEcjfli ऑऩये टय दो प्रिाय िे होते हैं ।
 in
 not in

in
This operator is used to find an element in the specified sequence.
It returns True if element is found in the specified sequence else it returns false.
इस ऑऩये टय िा उऩमोग लनकदय ष्ट अनुरभ भें एि तत्ि िो खोजने िे लरए किमा
जाता है । मकद तत्ि लनकदय ष्ट अनुरभ भें ऩामा जाता है तो मह True fjVuZ djsxk
अन्मथा मह False fjVuZ djsxk A
Ex-
s=” my name is mohan”
print (“mohan” in s)
not in
This operator works in reverse manner for „in‟ operator.
It will returns True if element is not found in the specified sequence and if element
is found then it will returns false.
मह ऑऩये टय ‘in’ऑऩये टय िे लरए रयिसय तयीिे से िाभ ियता है ।
है । मकद तत्ि लनकदय ष्ट अनुरभ भें ugh ऩामा जाता है तो मह True fjVuZ djsxk अन्मथा
मह False fjVuZ djsxk A
Ex-
s=” my name is mohan”
print(“mohan” not in s)
Identity Operators
The Identity operators compare the memory location of two objects. Hence it is
possible to know whether two objects are same or not.
आइडें कटटी ऑऩये टय दो ऑब्जेक्ट िी भेभोयी रोिेशन िी तुरना ियते हैं । इसलरए
मह जानना संबि है कि दो िस्तुएं सभान हैं मा नहीं।
There are two types of identify operator.
आइडें कटटी ऑऩये टय दो प्रिाय िे होते हैं ।
 is
 is not
is
It returns true if memory location of two objects are same else it returns false.
मकद दो ऑब्जेक्ट्स िी भेभोयी रोिेशन एि ही है तो मह True fjVuZ djsxk अन्मथा
मह False fjVuZ djsxk A
Ex :
a=10
b=10
print (a is b)

is not
This operator works in reverse manner for „is‟ operator. It will returns true if
memory location of two objects are not same and if they are same it return false.

मह ऑऩये टय 'is’ ऑऩये टय' िे लरए रयिसय तयीिे से िाभ ियता है । मकद दो
ऑब्जेक्ट्स िी भेभोयी रोिेशन सभान नहीं है तो मह True fjVuZ djsxk
औय मकद िे सभान हैं तो मह तो मह False fjVuZ djsxk
Ex :
a=10
b=10
print (a is not b)

You might also like