Docsity

Data types in python, Study notes of Computer Engineering and Programming

Partial preview of the text

Download Data types in python and more Study notes Computer Engineering and Programming in PDF only on Docsity!

| Wate Types 7 a Integers (int) - + Integers 18.0, Numenic Oata Fupecie Pathon - + Tekeger value 19 -wepresented by ‘int class. + T+ contains positive on negative esbole numbers (oaithout Functions oc Decirsals)- 7 + There is no Niet to how long an integer value L ean be. 7 ee Lo. - + You can convert other aie dyes +o an 5 inkegers ‘ using the ‘int 0 fausction.- J ay Float - ; _ r - ' | + Float ig a Numenc Oata type ‘io Python. f - Float value is wepmevsented by Float class. + I+ ‘9 9 veal ourcher RoSuaL a Floating - -peiot . crepresentation. 3 Teeter . b + I+ 1s- opecified.. bya. echacispel point. r « Tt 48 accuvete up to 15 decicoal points- F — — - - i Exarople for int. O and Ploat 0) data type + 5 . , i =10 ; =wi ("the type of a 13 2", type ad) . b= |. 67 . - . __ pict C'the typeof b 9." type (b)) 7 Output | ee . The type of a ‘ig 2 The type of b ‘9 2 ) ¢ <4 === —— ~— — J = a ____ OifPerenice beteseen Jot 0 re Pout Qui. «- £ Le € Feature 7 Tnkger <4 “Float | Defivitios lhote numbers csithout| Nurbers alith deciscal pa | decimal points potots. «yj Dedaration | e.g, a= 5 eg, y= S14" | Precision Lofinite precision Uroited precision Ff : mas et Operations Support Aevithrostie || Supports Avitbrodtie operations | Operations ‘ Tt Representation | Stored a8 binary | Stored ‘In LEEE idlii -_ numbers sithout af 754 Floating - eT Fractions E petot forrest. eT Accurracy Acetrrate fo counting May bave -roucd? ca) eT and discrete values | errors and eT Representation sssuco@T _Copversien Can be expliciHy Can be explicitly _ ba converted to Float. | eonvented to a0 _ al | Steger, rounding aaa . - — 74 | may occane ee Se i" 9 nN 7 8 ye we aytt TT Exampres | m= 5 ys 34 a as pct = —sd Pos : ai =—_+— “hr rs Date, | [ if - ; 45 st 3 - Iv Python , a Vist 5 19 q buil et ~' Hat can bold and ordered collection. + Whe use square brackets LT +o cveate a list areectly . _ : + + I+ can shored chements: of diferent dypes Urelegers ) Meat) Shéing, et). } + The data-types [ist ‘is an ordered sequence poet “ie outable and made up of one ov more elements. oe Se eee + A Siet 58 very useful to group together elements oF mixed “date typeo: i Tm + List “Indices also stest Promo °. 7 Exaropte | : thistist % = LY apple”, * banansi) * chewry”] prot (B iWishish) a - Gubpat L' apple’, ‘ banang’ , cherry’ 7] Methods of Net - @ append © - ‘Add an element to the cod of the Viet. : - @ copy - Returs o Shallow copy of the ist. @® Sort O- Sort the fist In ascending order (by default) te eebeken's *2eean @®@ clean 0 - Remove al) elements Prom the list. BS eset O- Tostarct ap element a} a specified” position - hd eourt () - Returns tre numben of Hmeo “4 specified - ._eferoent appre. So the Vist. ibe BY Tuples - - A tuple “Wo python 3 an ‘\goroutable ordered “eollection of eleroent. -Tuples ave aimilaneto lists but unlike lists, they cannot be changed after theie creation. - Tupkes ean hold elements of different dato +y pes. + The rain charactetistas of touples ave being ordered » heterogeneous and ‘Imrmubable. - + A toupte ‘is created. by plading: oll the. “ters Soside parantheses (1... Separated by -corornge . + Tuples ave onditen with wound brackets -— + Tuples ‘berms are orden .unchaogable » and aljecd duplicates valu. + Examples 2 = tibsadt thishupte = (" apple” . “banana”, “ chewry”) prot Libistuple) ~ - : Output : TR HAR ake eeret Capple! banana’, ‘ chewry') | Methote of Tuples - / @ count O - Returps, the numben of ¥imes a specified | valus occu “In _a_fupte. @ Index _© - Sesrch—otupte Searches the tuple Por a! specified valut aod weturns the position of | iesheve it swe