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

Nouha Thabet - Python Basics1

This document provides an overview of basic Python concepts like data types, variables, comments, printing, and type casting. It includes examples and explanations of common Python data types like strings, integers, floats, lists, tuples, dictionaries, boolean values and more.

Uploaded by

Ravikanth L
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)
12 views1 page

Nouha Thabet - Python Basics1

This document provides an overview of basic Python concepts like data types, variables, comments, printing, and type casting. It includes examples and explanations of common Python data types like strings, integers, floats, lists, tuples, dictionaries, boolean values and more.

Uploaded by

Ravikanth L
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 Basics1 Cheat Sheet

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

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
"​"​" This is a comment
x = {"Pi​nk",​"​Red​"} set
written in
x = frozen​set​({"P​ink​"​,"Re​d"}) froze​nset
more than just one line "​"​"
x = True bool
Python Variables x = b"Co​lor​" bytes

x = "How old are you ?" #x is of type str x = bytear​ray(8) bytea​rray


print(x) x = memory​vie​w(b​yte​s(8)) memor​yview
>>> How old are you ?
Get the data type of x : memor​yview
x = 25 #x now is of type int
x = "​Col​or"
print(x)
print(​typ​e(x))
>>> 25
>>> str

Python Data Types


Python Casting
Text Type: str
Casting is used to specify a type on to a variable and this is done
Numeric Types: int, float, complex
using constr​uctor functions.
Sequence Types: list, tuple, range Exam​ples
Mapping Type: dict x = int(5) #x = 5
x = int(2.8) ​ #x = 2
Set Types: set, frozenset
x = float(5) ​ #x = 5.0
Boolean Type: bool
x = float(​2.8) #x = 2.8
Binary Types: bytes, bytearray, memory​view

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


type(​var)

By Nouha_Thabet Not published yet. Sponsored by CrosswordCheats.com


cheatography.com/nouha- Last updated 6th December, 2019. Learn to solve cryptic crosswords!
thabet/ Page 1 of 1. http://crosswordcheats.com

You might also like