Chapter 4 :Introducing Python Object types
Everything is an object in Python: from simple numbers to strings.
The python conceptual hierarchy
- Programs are composed of modules
- Modules contain statements
- Statements contain expressions
- Expressions create and process objects
Python’s Core Data Types
- Numbers: 124, 12.3, Decimal(), Fraction()
- Strings: 'spam’, 'a\246'
- Lists: []
- Dictionaries: {}
- Tuples: ()
- Files: open()
- Sets: {}
- Other core types: Boolean, types, None
- Program unit types: Functions, modules, classes
- Implementation related types: Compiled code, stack tracebacks
Numbers
- int
- float
- complex
- decimals
- rationals
- sets
There are two waya to print every object in Python- with full precision(as-code repr) and the second is it’s user-friendly str.
If something looks odd, try showing it with a print function
Strings
Strings are used to record both textual information as well as arbitrary collection of bytes.
Index of string starts from 0. s[0] gives the first character of the string. s[-1] gives the last item from the end in the string s