This is a draft cheat sheet. It is a work in progress and is not finished yet.
Python Comments
Example 1 #This is a comment
|
Example 2 #This is a comment #written in #more than just one line
|
Example 3 """ This is a comment written in more than just one line """
|
Python Variables
x = "How old are you ?" #x is of type str print(x) >>> How old are you ? x = 25 #x now is of type int print(x) >>> 25
|
Python Data Types
Text Type: |
|
Numeric Types: |
|
Sequence Types: |
|
Mapping Type: |
|
Set Types: |
|
Boolean Type: |
|
Binary Types: |
bytes, bytearray, memoryview
|
Get the data type of a variable "var" |
|
|
|
Python Data Types Examples
Example |
Data Type |
|
|
|
|
|
|
|
|
x = ["Blue","Red","Yellow"]
|
|
x = ("Blue","Red","Yellow")
|
|
|
|
x={"Age":25,"Height":1.72}
|
|
|
|
x = frozenset({"Pink","Red"})
|
|
|
|
|
|
|
|
x = memoryview(bytes(8))
|
|
Get the data type of x : |
|
x = "Color" print(type(x)) >>> str
|
Python Casting
Casting is used to specify a type on to a variable and this is done using constructor functions. Examples x = int(5)
#x = 5 x = int(2.8)
#x = 2 x = float(5)
#x = 5.0 x = float(2.8)
#x = 2.8 |
|