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.
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 ratings0% 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.
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!") Example Data Type
x = "Color" list Python Comments x = 1 int Example 1 x = 1.2 float #This is a comment x = 2j complex Example 2 x = ["Blue","Red","Yellow"] list #This is a comment #written in x = ("Blue","Red","Yellow") tuple #more than just one line x = range(8) range Example 3 x={"Age":25,"Height":1.72} dict """ This is a comment x = {"Pink","Red"} set written in x = frozenset({"Pink","Red"}) frozenset more than just one line """ x = True bool Python Variables x = b"Color" bytes
x = "How old are you ?" #x is of type str x = bytearray(8) bytearray
print(x) x = memoryview(bytes(8)) memoryview >>> How old are you ? Get the data type of x : memoryview x = 25 #x now is of type int x = "Color" print(x) print(type(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 constructor functions. Sequence Types: list, tuple, range Examples 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, memoryview
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