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

Python Basics 1

This document is a Python cheatsheet that covers basic syntax and operations, including printing, control flow, comments, variables, arithmetic operations, relational operators, logical operators, user input, and loops. It provides examples for each category, demonstrating how to use Python for various tasks. The document serves as a quick reference for Python programming concepts.

Uploaded by

kahfiimarhas
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)
18 views1 page

Python Basics 1

This document is a Python cheatsheet that covers basic syntax and operations, including printing, control flow, comments, variables, arithmetic operations, relational operators, logical operators, user input, and loops. It provides examples for each category, demonstrating how to use Python for various tasks. The document serves as a quick reference for Python programming concepts.

Uploaded by

kahfiimarhas
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 Cheatsheet

Print Control Flow


print('Hello World!')
if grade >= 90:

print(1000)
print('A')

print(3.14)
elif grade >= 80:

print(True)
print('B')

elif grade >= 70:

print('C')

else:

Comments print('D')
# I’m a comment!

print('Gabby') # I’m also one T.T Relational Operators


a == b # equal to

a != b # not equal to

Variables a >b # greater than

a <b # less than

secret_num = 42 # int
a >= b # greater than or equal to

gravity = 9.81 # float


a <= b # less than or equal to
username = '@snoopdogg' # str

earth_is_flat = False # bool


Random Number
Arithmetic Operations import random

num = random.randint(1, 9)
sum = 23 + 18

difference = 30 - 8

product = 10 * 2.5

quotient = 81 / 9

remainder = 76 % 4

Logical Operators
exponent = 2 ** 3
a and b # True if both are true

a or b # True if at least one is True

not a # True if a is false

User Input
username = input('Enter your name: ')

age = int(input('Enter your age: '))


Loops
# While loop

while coffee < 1:

print('Tired of Python ')

String Interpolation

# For loop

print(f'The square of {i} is {i*i}')


for i in range(10):

print(i)

Codédex

You might also like