CSC108H5 Lecture 4: CSC108H5 LECTURE 4-DATA TYPES- "NUMBERS , BOOLEANS"
CSC108H5 verified notes
4/13View all
Document Summary
Lecture 4: data types-numbers: python has four built in data types for numbers, only three data types of numbers are supported in python 3: integer, floating point numbers and complex numbers. Integer: these are whole numbers without decimals, can be positive or negative numbers but no decimals. Integers have unlimited size in python 3: examples, regular integers: 793, -25, 9, octal integers (base 8): we have to use prefix (cid:858)0o(cid:859) or (cid:858)0o(cid:859) to indicate an octal number. 7: hexadeci(cid:373)al literals (cid:894)(cid:271)ase (cid:1005)(cid:1010)(cid:895): the(cid:455) ha(cid:448)e prefi(cid:454) (cid:858)(cid:1004)x(cid:859) or (cid:858)(cid:1004)(cid:454)(cid:859) 2572: bi(cid:374)ar(cid:455) literals (cid:894)(cid:271)ase (cid:1006)(cid:895): the(cid:455) ha(cid:448)e prefi(cid:454) (cid:858)(cid:1004)b(cid:859) or (cid:858)(cid:1004)(cid:271)(cid:859) >>>oct(7) (cid:858)(cid:1004)o(cid:1011)(cid:859: example: convert integer 2572 to hexadecimal literal. >>>hex(2572) (cid:858)(cid:1004)(cid:454)(cid:1004)(cid:272)(cid:859: example: convert integer 12 to binary string. >>>bin(12) (cid:858)(cid:1004)(cid:271)(cid:1005)(cid:1005)(cid:1004)(cid:1004)(cid:859: the result can be stored to a variable as well and then called for, example: >>>x (cid:858)(cid:1004)(cid:454)a(cid:1004)(cid:272)(cid:859: we use command type() to see the created object type which is stored in variable x, example: