Download as pdf or txt
Download as pdf or txt
You are on page 1of 10

e.g.

, Regular Expressions,Garden, Kitchen, Audio

LOGIN or REGISTER

Python Cheat Sheet Cheat Sheet


by jinnymuids

Addition

string + string combine together

string + number crash

number + number math - addition

Functions

print () displays information on the screen

input () receives information from the user

int () converts a value to an integer

str () string ("word") can be everything

float () change number to be decimal number

# comment(one line)

" " " .......... " " " comment(many lines)

import random + random.choice() pick random item in the list


:
Math

+ plus

- minus

* multiple

/ divide

% remainder (4%2)-> 0

** exponent 2**3 -> 2^3

== equal to

!= not equal to

< less than

> more than

<= less than or equal to

>= more than or equal to

Code2

shoppinglist = ('tshirt', 'pants', 'socks')


 for myvariable in shoppinglist:
     print (myvariable)

print (shoppinglist(1))

for number in range(5):


    print (number)
:
Vocabulary

Variable holds a value and can be changed

String a list of characteristics such as numbers, letter, symbols

Syntax Grammar

Modulo Remainder %

Integer Real number

Floating Point Decimals

Boolean True/False

== equal != not equal

Syntax Error make impossible to the parse

Name

firstname = input (" What is your first name? ")


lastname = input (" What is your last name? ")
fullname = ( firstname + " " + lastname )
print (fullname)
letternumber = int(input( " What is letter number? " ))
if letternumber > len(fullname):
    print ( " invalid letter number, try again! " )
else:
    letter = (fullname[letternumber])
    print (letter)
    numberletter = int(input(" How many times to print letter? "))
    if numberletter > 100:
        print (" Too many letters to print! " )
        else:
            print ( letter * numberletter )
:
Code1

# Create a program that recieve a number from the user


# from that number on the same line

#recieve the number from the user as a string


user_number = input

#convert the user number to an integer


number = int(user_number)

#setup the countdown string


countdown_string = ""

while number > ():#the number is greater than 0)


    remainder =
    print (number)
    #binary_string =

#output should look like this


# if the user enters 5:
# 5 4 3 2 1
print (countdown_string)

Multiplication and Exponents

string * number combine that string

string * string crash

number * number math - multiply

string ** string crash

number ** number math-exponent

string ** number crash


:
Code

mystring = "hello"

print (mystring)

firstname = input ("What is your firstname?")

lastname = input ("What is your lastname"?)

fullname = firstname + " " + lastname

print(fullname)

letternumber = int(input("What is letter number? " ) )

if lettername > len(fullname):

print ("invalid letter number, try again! " )

else:

letter = (fullname(letternumber) )

print (letter)

numberletter = int(input ( "How many times to print letter " ) )

Area of Circle

while 2==2:
    #Ask the user for a radius of a circle
    user_radius = input("What is the radius? ")

    #Convert the given radius to a floating point


    radius = float(user_radius)

    #make a variable called pi


    pi = 3.1415

    #Calculate the area of the circle using exponents


    area = pi radius * 2

    #display the area of the circle to the user


    print ("The area of the circle is",area)
:
Binary

user_number = input("Enter a number to convert to binary:")


number = int(user_number)
binary_string = ''
while (number>0):
       remainder = number % 2
       binary_string = str(remainder) + str(binary_string)
       number = number // 2
print ("Binary string is '', binary_string)

Download the Python Cheat Sheet

Cheat Sheet
:
2 Pages

PDF (recommended)

 PDF (2 pages)

Alternative Downloads

 PDF (black and white)


 LaTeX

Created By

jinnymuids

Metadata

Languages: English
:
Published: 15th February, 2016

Last Updated: 12th May, 2016

Rated: 4 out of 5 stars based on 1 ratings

Comments

No comments yet. Add yours below!

Add a Comment

Your Comment

Your Name

Your Email Address

Your Comment

Post Your Comment


:
Latest Cheat Sheet Random Cheat Sheet

 3 Pages  100 Pages

     (0)      (0)

Q2 MIL Reviewer Cheat Pico-8 Cheat Sheet


Zoltan
Sheet
 3 Feb 19, updated 26 Feb 19
STEM 12- Q2 MIL Reviewer
 deleted

Dementia306

 22 Jan 23
 test, information, media

About Cheatography
Cheatography is a collection of 5598 cheat sheets and quick references in 25 languages for
everything from language to linux!

Behind the Scenes


If you have any problems, or just want to say hi, you can find us right here:

DaveChild

SpaceDuck
:
Cheatography

Recent Activity
Dementia306 updated Grade 12 Philosophy reviewer.
5 hours 7 mins ago

ha.an published 12.2 Demography - SBI4U1.


2 days 15 hours ago

Sana_H published Statistics in Behavioral Sciences.


4 days 22 hours ago

© 2011 - 2023 Cheatography.com | CC License | Terms | Privacy

 Latest Cheat Sheets RSS Feed


:

You might also like