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

Python

The document outlines basic Python operations and variable assignments, including arithmetic operations and string manipulation. It explains how to define variables, perform calculations, and access string indices. Additionally, it highlights common errors and the use of functions like len() to determine string length.

Uploaded by

Abdiel Hernandez
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views1 page

Python

The document outlines basic Python operations and variable assignments, including arithmetic operations and string manipulation. It explains how to define variables, perform calculations, and access string indices. Additionally, it highlights common errors and the use of functions like len() to determine string length.

Uploaded by

Abdiel Hernandez
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Python

Elements that the language already know.

+ - addition
- - Subtraction
* - multiplication
/ - float division (number has decimals)
// - integer division (exact division with whole numbers
% - restante
_ - previews answer

\n – enter (next line)


‘’ – text
r‘’ – raw text, so everything in quotes will be text
'marley\'s "laptop"' – marley’s “laptop”

Variables
x = 2 - x variable value is 2
x+3 - the anser will be 5 because x value is 2 and we add 3 equals 5
y = 3 - y variable value is 3
x+y - python will be adding x and y values that equals 5
x=9 - x value will change to 9, will not be 2 anymore

abc - will be an error, because variables are not define


name = ‘class’
name + ‘rock’ - answer will be ‘class rock’

name value is class, if we break name value will have 5 values (starting with 0) because class has 5
letters, so
name[0] = ‘c’
name [-1] = ‘e’ - because starts from the end
name [4] = ‘e’ - because is the last letter
name[0:2] = ‘cl’ - says selects letters from 0 to before 2
name[1:3]= ‘la’ -says select letters from 1 to before 3
name[:4]= ‘clas’ -from beginning to before 4
name[1:]= ‘lass’ -from 1 to the end
name[3:10]= ‘ss’ -from 3 to before 10 but because there is nothing from 9-10 will be in blank
name[0] = “C” -error, you can’t change the value of a single letter
myname = “Marley Hernandez”
len(myname) = 16 - tells you the length of the value (how many characters it has, even with
spaces)

You might also like