Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Class notes

Python cheatsheet learn python within weeks

Rating
-
Sold
-
Pages
68
Uploaded on
20-01-2025
Written in
2024/2025

This document helps to learn python programming within weeks. By following the the instructions given in the document you can excel in python with minimum effort and maximum effect.

Institution
Course

Content preview

Python Cheatsheet for
Quick Reference
WEEK 1
1. print() : method to print on the console.

print(“Hello World”)

2. Variables are used to store values. The values can be
number, text etc.

3. a = 10 #int

n = 10.3 #float
s = “Student” #str
t = True #bool
4. input() method is used to take input from user in the
form of string
5. type() method is used to get datatype of a variable or
value
6. Typecasting:to change a datatype from one to another.
a = int(10.1) #This will convert 10.1 to 10
a1 = int(10.1) #This will convert 10.1 to 10
b = float(10) #This will convert 10 to 10.0
c = str(10.3) #This will convert 10.3 to ‘10.3’
d = bool(0) #False
e = bool(10) #True
f = bool(-10) #True
g = bool(‘India’) #True
i = bool(‘’) #False

7. Arithmetic operators

 -> Addition (int or float) , Concatenation (str)

, - -> Subtraction
* -> Multiplication (int or float) , Repetition (str)
/ -> Division
// -> Floor Division (Integer division)
% -> Modulus operator (remainder after division)
** -> Exponentiation (power)
8.Relational operators(It will compare and give True or False)
> -> Greater than
< -> Less than
>= -> Greater than or equal
<= -> Less than or equal
== -> Equal
!= -> Not equal
9. Logical operators
and -> Returns True if both LHS and RHS are true
or -> Returns False if both LHS and RHS are false
not -> Returns negation of given operand
10.Strings
s1 = ‘Hello’
Or
s2 = “World”
11.String indexing (starts from 0)
s1[0] -> H
s1[-1] -> o
12.String slicing
s1[0:3] -> Hel
13.String comparison - (order in English dictionary)
‘apple’ > ‘one’ -> False
‘apple’ > ‘ant’ -> True
14.String length
len() method gives length of a string.
len(s1) -> 5

WEEK 2

,1. Comments: A section of our program that is ignored by the
compiler(to increase the readability of the code).

-> # This is a comment
-> ‘’’ This is
A multiline
Comment ‘’’

2. Dynamic Typing: The type of a variable in Python is
determined by the value it stores and changes with it.

-> message = 'Hello'

-> message = 10



3. Multiple Assignments

Assign multiple values or the same value to multiple variables
x, y, z= 1 , “Hi” , False x=y=z=100
print(x,y,z) -> 1 “Hi” False print(x,y,z) -> 100 100 100

4. Del x - > Delete the reference x

5. Shorthand Operators

+= , -= , *= , /= ….etc , Basically any operator with the “=” sign.
num = num + 1 is same as num +=1
num = num * 2 is same as num *=2

6. in operator - Tells whether something is inside/part of the other thing
(similar to the English definition)

“ IT “ in “ IIT Madras “ - > True # searches for the string “IT” in “IIT Madras”
“ ads “ in “ IIT Madras “ - > False

7. Chaining Operators - Using multiple relational operators (<,>,==,<=,>=,!
=) together

x=5
print( 1 < x < 6 ) - > True

, print( x < 2 * x < 3 *x > 4 *x ) - > False
# above can be looked as
print( 5 < 10 < 15 > 20 ) - > False # 15 is not greater than 20

8. Escape Characters - To insert characters that are illegal in a string, use an
escape character.

An escape character is a backslash \ followed by the character you
want to insert.
print(‘It’s Raining’) - > Error #All Characters after second ‘ (single
quote) are not considered as a part of the string (s Raining)
# So we use \ before the ‘ print(‘It\’s Raining’) - > It’s Raining
Other Escape Characters - \n : Cursor moves to the next line
\t: Shifts cursor by 5 spaces

9. Multiline Strings: Similar to multiline comment

S = ‘ ‘ ‘ A multiline
String ‘ ‘ ‘
print(S) - > A multiline
String

10. In Python, variable names must start with a letter (a-z, A-Z) or an
underscore (_), and can be followed by letters, digits (0-9), or underscores.
They are case-sensitive and cannot use Python-reserved keywords.
Variable name cannot start with any digit (0-9)

Written for

Course

Document information

Uploaded on
January 20, 2025
Number of pages
68
Written in
2024/2025
Type
Class notes
Professor(s)
Satayadev nandakumar
Contains
All classes

Subjects

$8.89
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller
Seller avatar
aleenaroohus

Get to know the seller

Seller avatar
aleenaroohus Gtech
Follow You need to be logged in order to follow users or courses
Sold
-
Member since
1 year
Number of followers
0
Documents
1
Last sold
-

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Recently viewed by you

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

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions