Skip to content
Python
Share
Explore

icon picker
Python

Printing

The print function in Python is used very often to output something.
print(“name”)
Output -> name

What Integers, Variables, Lists, Strings are


Integers -> Numbers
Strings -> Words with “”
Variables -> A place where you can store data
List -> A type of data that allows you to store multiple things
For example:
Integer: 2
String: “Hello”
Variable: name = “Sally”
List: list1 = [1, 3, 5, 2, 4]
How would you print Integers, Variables, Lists, and Strings?
Integers: print(______[write in integer, no “”])
Variables: print(_______[write in variable, no “”])
Strings: print(“______”[You can write in anything you want as long as it’s in quotes])
Lists: print(_______[Write the variable to store in the list]])
Examples:
Printing Integers:
Printing Varibles:
Printing Strings:
Printing Lists:

Input()


What is input?
→ Input is when the user gets to choose

For example:
print(“Which color do you like best? Pink or blue.”)
Color = input()
print(“What is your name?”)
Name = input()
print(“Hello, my name is ” + Name + “. And I like the color ” + Color + “!”)
Output:
→ Hello my name is Sumay. And I like the color blue!
As you can see input() is really cool! Let’s see if we can expand on it!

Indexes


Food = [“Apple”, “Banana”, “Peach”, “Watermelon”, “Kiwi”]
^ ^ ^ ^ ^
0 & -5 1 & -4 2 & -3 3 & -2 4 & -1
Indexes: They point to a specific element in a list
Indexes in Python always start with 0
Positives:
print(Food[0]) —> Apple
print(Food[1]) —> Banana
print(Food[2]) —> Peach
print(Food[3]) —> Watermelon
print(Food[4]) —> Kiwi

Negatives:
print(Food[-5]) —> Apple
print(Food[-4]) —> Banana
print(Food[-3]) —> Peach
print(Food[-2]) —> Watermelon
print(Food[-1]) —> Kiwi

Printing with +

Sometimes you want to print multiple things in one print statement. This is made possible by using a + sign in your print statements!
Word = "Carrots"
print("My favorite food is " + Word + ".")
Output → My favorite food is Carrots.
--
Numbers = [1,2,3]
Numbers2 = [4,5,6]
print(Numbers + Numbers2)
Output->[1,2,3,4,5,6]
all_numbers = (Numbers + Numbers2)
print(“These are some of the numbers I know! ” + all_numbers)
Output->These are some of the numbers I know! [1,2,3,4,5,6]

len()


len() it counts how many items are in a list.
Number = [1,2,3,4,5,6,”Hello”]
print(len(Number))
Output —> 7
Food = [“Pizza”, “Cookie”, “Orange”]
print(len(Food))
Output -> 3

Append


Monkey = [“M”, ”o”, ”n”, ”k”, ”e”]
Monkey.append(“y”)
That adds to the list so it has the word “monkey”.
print(Monkey)
Output —> ['M', 'o', 'n', 'k', 'e', 'y']


Del()


Del() is used to delete things from a list.
Syntax:
del(list name[index])
x = [1,2,3,4,6,”hello”]
print(x)
Output —> [1,2,3,4,6,’hello’]
I wanna delete 6
del(x[4])
print(x)
Output —> [1,2,3,4,’hello’]
len(x)
Output—> 5

If and Else Statements


Box = “toy”
If Box == “toy”:
Box = empty
Else:
Box = toy

Why is the difference between = and ==?
= means assign == means compare.

Elif


Elif is for when there is another if
For example:
apple = input()
If apple == “red”:
print(“Your apple is red!”)
Elif apple == “green”:
print(“Your apple is green!”)
Else:
print(“Your apple is yellow!”)

Casting

Casting is converting integers into string and vice-versa

For example:
How would you change 3 into a string.
str(3)-> “3”
Syntax:
str(*integer*)
Or a string into an integer.
int(“3”)-> 3
Syntax:
int(*string*)

Functions


What are functions?
Functions are quick ways of running big amounts of code.

Syntax:
def *Function name*():
*What you want the function to do*
*Function name*()
Instead of:
Output—> Hi
My
Name
Is
Bob
We can make a function:
Output—> Hi
My
Name
Is
Bob
The thing about a function is that you can do it multiple times!
Printing()
Printing()
Output—> Hi
My
Name
Is
Bob
Hi
My
Name
Is
Bob
You can also have customizable functions where you have to input values in the () in your function.
By adding (firstname, lastname, age) in the function you make it so that when you call the function, you have to add those values.

How to make things uppercase


String1 = “Hello”
print(String1.upper())
Output → HELLO
print(String1.lower())
Output → hello
13. How to make things lowercase
String1 = “HELLO”
print(String1.lower())
Output → hello

For loops


A For loop loops through a list.
x = [1,2,3,4,5]
If you want to change something in a list you can do this:
x[0] = 2
print(x)
Output—> [2,2,3,4,5]
What if you want to change x into:
[3, 3, 4, 5, 6]
That would take a long time.
So we can make a For loop.
This for loop would add 1 to every element of the list.
Syntax:
For *variable to hold the current element of the list* in *list*():
___________
___________
Then it does whatever you put for the for loop to do and does it to every element in the list.
For i in x():
i = i + 1

How to keep track of points


How would you keep track of points in python?
→ Unfortunately there is no built in function that keeps track of points. So we have to build it ourselves.
Let’s get started!
# First we make a variable called points.
Points = 0
# We start with 0 because we start out with no points
# Now, we need to have something to put points for.
# So, we are going to make a quiz!
Want to print your doc?
This is not the way.
Try clicking the ⋯ next to your doc name or using a keyboard shortcut (
CtrlP
) instead.