0% found this document useful (0 votes)
4 views

Python reviewer

The document provides an overview of basic Python syntax, including how to take user input, print output, and create variables. It explains various data types such as strings, integers, floats, lists, tuples, sets, and dictionaries, along with their characteristics and how to manipulate them. Additionally, it covers typecasting and the use of the range function for generating sequences of numbers.

Uploaded by

dmcmorada26
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Python reviewer

The document provides an overview of basic Python syntax, including how to take user input, print output, and create variables. It explains various data types such as strings, integers, floats, lists, tuples, sets, and dictionaries, along with their characteristics and how to manipulate them. Additionally, it covers typecasting and the use of the range function for generating sequences of numbers.

Uploaded by

dmcmorada26
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Basic syntax:​

input()
#takes an input from the user

print()
#outputs whatever is in the parentheses​

#random text​
#Lines following a hashtag will become comments and the will be ignored by the program but
can be seen by you​

x=213, x=”Chris”
#Creates a variable (x and the values are placeholders and can be anything). Multiple value
variables also exist as see below​

X,y,z =”Hi”,”Hello”,”Kamusta”​
#Creates multiple variables with the first value being assigned to the first variable, the second
value to the second variable and so on​

Data types
Str​
#The data type used for characters which can be anything​

Int
#integers​

Float
#numbers with decimal points ​

Range
#description below​

List
#description below​

Tuple
#description below

Set​
#description below
Typecasting
Is converting strings to other data types by enclosing them in the desired data type, for example:
x=int(input())
#the data type of the input is now int instead of str​

Sequence types

Lists store multiple changeable values. For example:


Thislist = [“Comsci”,”Chem”,”Phys”]

Tuples are lists that are unchangeable and use ( ) instead of [ ]. For example:​

Range is a function used to generate numbers. It works like this​



For x in range(start, stop, step)
print(x)

The x is simply a variable and how the function works is that it will return the numbers from the
start value until the number before the stop value. The step value determines the difference
between each value. For example​

for i in range(1, 10, 2):
print(i)

Output:
1
3
5
7
9

Changing list values


Thislist[2] =”element”
#Calls an index and assigns it a new element (

Thislist.append(“element”)
#Adds an element to the end of the list

thislist.remove(“element”)​
#removes an element from the list
Set
Storage of multiple, unordered, unindexed, unchangeable values in one variable

thisset={“uno”,”dos”,”tres”}

thisset.add(“quatro”)
#adds an element

thisset.remove(“uno”)
#removes an element

Dictionaries
Storage of multiple values with no duplicates

To create:

thisdictionary = {

“name”:”Jojo”,
“subject”:”Math AA HL”,
“status”:”failing”

To access:
print(thisdictionary[“name”])

Will return Jojo

To change value:

thisdictionary[“name”]=“Javy”

To return value and then remove:

thisdictionary.pop(“status”)

You might also like