100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached 4.2 TrustPilot
logo-home
Class notes

BEST Python+Syntax+Cheat+Sheet+Booklet (Detailed)

Rating
-
Sold
-
Pages
16
Uploaded on
09-04-2022
Written in
2022/2023

BEST PYTHON SYNATAX XHEATSHEET

Institution
Course










Whoops! We can’t load your doc right now. Try again or contact support.

Written for

Institution
Course

Document information

Uploaded on
April 9, 2022
Number of pages
16
Written in
2022/2023
Type
Class notes
Professor(s)
Angela yu
Contains
All classes

Subjects

Content preview

PYTHON CHEAT SHEET
100 DAYS OF CODE
COMPLETE PROFESSIONAL
PYTHON BOOTCAMP

BASICS


Print

Prints a string into the console. print("Hello World")


Input

Prints a string into the console, input("What's your name")
and asks the user for a string input.



Comments

Adding a # symbol in font of text #This is a comment
lets you make comments on a line of code. print("This is code")
The computer will ignore your comments.



Variables

A variable give a name to a piece of data. my_name = "Angela"
Like a box with a label, it tells you what's my_age = 12
inside the box.



The += Operator

This is a convient way of saying: "take the my_age = 12
previous value and add to it. my_age += 4
#my_age is now 16



www.appbrewery.com

, PYTHON CHEAT SHEET
100 DAYS OF CODE
COMPLETE PROFESSIONAL
PYTHON BOOTCAMP
DATA TYPES


Integers

Integers are whole numbers. my_number = 354


Floating Point Numbers

Floats are numbers with decimal places. my_float = 3.14159
When you do a calculation that results in
a fraction e.g. 4 ÷ 3 the result will always be
a floating point number.


Strings

A string is just a string of characters. my_string = "Hello"
It should be surrounded by double quotes.



String Concatenation

You can add strings to string to create "Hello" + "Angela"
a new string. This is called concatenation. #becomes "HelloAngela"
It results in a new string.



Escaping a String

Because the double quote is special, it speech = "She said: \"Hi\""
denotes a string, if you want to use it in print(speech)
a string, you need to escape it with a "\"
#prints: She said: "Hi"


www.appbrewery.com

, PYTHON CHEAT SHEET
100 DAYS OF CODE
COMPLETE PROFESSIONAL
PYTHON BOOTCAMP



F-Strings

You can insert a variable into a string days = 365
using f-strings. print(f"There are {days}
The syntax is simple, just insert the variable in a year")
in-between a set of curly braces {}.




Converting Data Types

You can convert a variable from 1 data n = 354
type to another. new_n = float(n)
Converting to float:
float() print(new_n) #result 354.0
Converting to int:
int()
Converting to string:
str()




Checking Data Types

You can use the type() function n = 3.14159
to check what is the data type of a type(n) #result float
particular variable.




www.appbrewery.com
$7.99
Get access to the full document:

100% satisfaction guarantee
Immediately available after payment
Both online and in PDF
No strings attached

Get to know the seller
Seller avatar
hppavilion

Get to know the seller

Seller avatar
hppavilion IIT BOMBAY
Follow You need to be logged in order to follow users or courses
Sold
0
Member since
3 year
Number of followers
0
Documents
2
Last sold
-

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Frequently asked questions