Basic Datatypes of Python
- Jino Shaji
- Jan 7, 2015
- 1 min read
Updated: Jun 9, 2020
Basic Datatypes of Python
•Integers (default for numbers)
z = 5 / 2 # Answer is 2, integer division.
•Floats
x = 3.456
•Strings
Can use “” or ‘’ to specify. “abc” ‘abc’ (Same thing.)
Unmatched ones can occur within the string. “matt’s”
Use triple double-quotes for multi-line strings or strings than contain both ‘ and “ inside of them: “““a‘b“c”””
Whitespace
is meaningful in Python: especially indentation and placement of newlines.
–Use a newline to end a line of code. (Not a semicolon like in C++ or Java.) (Use \ when must go to next line prematurely.)
–No braces { } to mark blocks of code in Python… Use consistent indentation instead. The first line with a new indentation is considered outside of the block.
–Often a colon appears at the start of a new block. (We’ll see this later for function and class definitions.)
Comments