0% found this document useful (0 votes)
9 views1 page

Python - Introduction Cheat Sheet

This cheat sheet provides a quick introduction to Python, including how to print 'Hello World' and use comments. It outlines various Python data types such as str, int, float, list, tuple, dict, set, and more, along with examples for each. Additionally, it explains how to determine the data type of a variable using the 'type()' function.

Uploaded by

mohamedsahith904
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views1 page

Python - Introduction Cheat Sheet

This cheat sheet provides a quick introduction to Python, including how to print 'Hello World' and use comments. It outlines various Python data types such as str, int, float, list, tuple, dict, set, and more, along with examples for each. Additionally, it explains how to determine the data type of a variable using the 'type()' function.

Uploaded by

mohamedsahith904
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Python - Introduction Cheat Sheet

by Nouha_Thabet via cheatography.com/103894/cs/21303/

Hello World in Python Python Data Types Examples

print​("Hello World!​") Exam​ple Data Type


x = "​​Co​lor​" list
Python Comments
x = 1 int
Example 1
x = 1.2 float
#This is a comment
x = 2j complex
Example 2
x = ["Bl​​ue​"​,​"​Red​​"​,​"​Ye​​llo​​w"] list
#This is a comment
#written in x = ("Bl​ue",​"​Red​"​,"Ye​llo​w") tuple
#more than just one line x = range(8) range
Example 3 x={"Ag​e":2​5,"H​eig​ht":​1.72} dict
"​"​"
x = {"Pi​nk",​"​Red​"} set
This is a comment
x = frozen​set​({"P​ink​"​,"Re​d"}) froze​nset
written in
more than just one line "​"​" x = True bool

x = b"Co​lor​" bytes
Python Variables x = bytear​ray(8) bytea​rray
#code x = memory​vie​w(b​yte​s(8)) memory​view
x = "How old are you ?" #x is of type str
Get the data type of x :
print(x)
x = "​Col​or"
#output
print(​typ​e(x))
>>> How old are you ?
>>> str
#code
x = 25 #x now is of type int
print(x)
#output
>>> 25

Python Data Types

Text Type: str

Numeric Types: int, float, complex

Sequence Types: list, tuple, range

Mapping Type: dict

Set Types: set, frozenset

Boolean Type: bool

Binary Types: bytes, bytearray, memory​view

Get the data type of a variable "​var​"


type(​var)

By Nouha_Thabet Published 7th December, 2019. Sponsored by Readable.com


cheatography.com/nouha- Last updated 6th December, 2019. Measure your website readability!
thabet/ Page 1 of 1. https://readable.com

You might also like