0% found this document useful (0 votes)
2 views19 pages

Python

The document provides an overview of various data types in Python, including Number, String, List, Tuple, Dictionary, and Set, along with their characteristics and examples. It also covers input and output operations, type conversion, and control statements such as if, if-else, and loops. Each section includes source code snippets to demonstrate the usage of these concepts in Python programming.

Uploaded by

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

Python

The document provides an overview of various data types in Python, including Number, String, List, Tuple, Dictionary, and Set, along with their characteristics and examples. It also covers input and output operations, type conversion, and control statements such as if, if-else, and loops. Each section includes source code snippets to demonstrate the usage of these concepts in Python programming.

Uploaded by

dassandeep2027
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
err stir wor Ee BA 8c aigca (vata TYPES) qa 8 ag S21 ay Ha BH 1, Fa (Number) 2, fégn (String) 3, fer (List) 4, 274 (Tuple) 5, BeeHI (Dictionary) 6. Bz (Set) ‘SEX (Number) Number Data Types % a4 war ea &— 1. Integer Number Data Type 2. Floating-point Number Data Type 3. Complex Number Data Type Note : type() function I ZeaHTe data type check ea % fore fra Se 21 1. Integer Number Data Type—Integer data type 4 normal numeric values @t #1 integer numbers % arqifena fees ael stat 81 2. Floating-point Number Data Type—Floating-point numbers ¥ srqriifsa feey Gra @i Python ¥ floating-point number % ferm ang etn wet et 1 3. Complex Number Data Type—Complex data type ‘a + bj’ #8 form ¥ erat #1 S58 a’ real part @at @ 3H ‘b’ imaginary part état ZI int Float complex | 10 20.0 34143 | REA (String) String characters #1 set a1 @1 characters; letters, numbers 4 special symbols a aaa i Python ¥ fT single(“ *) aT double(" ") quotes % A= fer STA 1 String arate (immutable) data type 21 $8 data type * items #1 values change sal ah st Bat 21 Source Code : — | strl = "Hello World" str2 = "Hello Friends" | \ print (str1) print (str2) sarge FAT (2587.14) 206 Output : Hello World Hello Friends ‘SHRM Programming Languages # string @ index # print frat Sat 31 seh san Python ¥ «ft string #1 indexes @ print fer" Sta @1 String % IA Veet character 4 index ‘8 Ye ett 2 sik string Ft waa snfera index’ eet 21 Positive index 012345 6 78910 [Hiellilo| |Wiojr -11-10-9-8-7-6 -5 -4-3. Negative index Source Code : ee oe str = "Hello World" print ("First letter in string :", str[0]) Print ("Last letter in string :", str[-1}) print ("Second last letter in string :", str[{-2]) Output : First letter in string : # a : Last letter in string: a Second last letter in string ; EEX] fer (ist) oe Python % list data type # wa ‘FART items a : P s A separate fren Sra a List % @# items @ square bracket (DD & Fez close tite ae a cot . _List = Bye (compound) data type @ faa frat of data types & items fare at FFA \list ts uftere (mutable) data type @1 € data type 3 it 2 ji ara th ems @ values change #1 Source Code ; list = (1, BT 81 US item B co "Hello", 6, 7) for i in dist ; Print (i) eae st er RET ie BRAGA cxc1 (tuple) Python % tuple data type Fue 8 Sa items Fa ZF list data type Ga A star #1 ez G item #1 comma(,) 4 separate far ITH V1 Tuple % AH items 1 wre (parenthesis) (() ¥ FR close Frat Tat BI Tuple T compound data type @ fara fare Ht data types * items fee wwe 1 tuple U& immutable data type 1 3 data type ® items # values change 74 Ft HT wat 21 Source Code : tuple = (1, "Hello", 6.7) for i in tuple : print (i) tuple(0) = 3 #trying to changing Oth index print (tuple (0)) Output : : Hello 6.7 {most recent call last): Trace 3 #trying to changing Oth index tuple [0] = TypeError: ‘tuple’ object does not support item assignment ERY ezxater (Dictionary) _. Dictionary Data Type in Python Pat 81 & key value % pair #1 comma. : Dictionary Data type # keys ait values #4 pairs ) @ ait key ait value @ colon(:) & separate frat REE RTH (en) 208 mat #1 Dictionary % ®t keys sit values @r curly aeons eae a & immutable data type @1 $8 data type % items #t values change wad @ Source Code : dict = {1:"H", 5:"e", 7:71", 8: , 920") print (dict[5]) print (dict{9]) Output : e ° EA Bc (set) Set Data Type items #1 Heraftert BYE (unordered collection) at 21 set 3 fea BH RG item 7H Aa V1 AT duplicate item fra stat 2 a 3a remove fat Sat 21 set data type ® items #7 curly braces ({}) 3 3r=x fear ara 21 Source Code : : setl = {"Ram", "Sita", "Geeta")} for i in setl: print (i) Output : Ram Sita Geeta aay Ve (CHARACTER SET) Python aah ASCH Steet az a sein * fe (UNICODE) = ea #1 ASCH ae eH eae (2.7) sf apts (Subset) @ Se 8 ae Steet de ar wae ee, a 010 Aye Fs wie defcalculate_circle_@ area = [Link]*radius**2 rea (radius) : return area le radius = 5 : ee = calculate circle_area(circle_radius) print (“Ga SARA: circle_area) # ofa sate print (‘Stora wera @ 7a ZI”) wa waem 3, eat ‘math Geared a arefed fea 2, freer sein eH ‘calculate_circle_area’ WH Trawr 4 fara ai hae 8 oa ga & aaHe ST va aa & few UE (x) Seam fee 31 eae BH sia eH eA ga Aree fie fran a1 sia FH, SA eH ‘dea fie fear @ sit Sema at ware fen 31 BA wg ed sisege sitter (INPUT AND OUTPUT OPERATION) FAYE EVA (Input) Function) ‘Ja Python 4 User 8 $e GF Bt ard sr @ 7a ‘input()’ function a eta fare are 21 input ("Type some Text") Parameter : So 8 i i cs cn Text: thee (Optional). User #4 input Se sak at q we $s text fea Example for ‘input()’ Function Source Code : a = input (" Enter your name: ") Print (" Your name is", a) Output : Enter your name : Ram Your name is Ram ye cs or Rr 2011 — + True Body of else t Body of elif Source Code : a=5 b=5 if(a < b) print(" a is less than b") elif(a > b) print (" ais greate " else : r than b") print ¢™, aor ser Rr Output : [e is equal to b 6.2} aft ee (Loopine STATEMENTS) oe While Loop Loop & @ statement ara execute I 8 Looping # 283aq (indentation) = at nea Bat 2 while loop * ararta wa aa condition true Stet 2 aa aa Statement execute Sal teat | at 74 condition false a unt @ aa loop #1 execution ea amt 21 Syntax for while Loop while (expression) 2e while statement (s) Example for while Loop Source Code : Z- ¢ while. (a < 10) Print ("Value a is " a=ar eae Output : Value 7 a) Value Value Value Value Value Value Value Value Value

You might also like