PHYTON Öffentlich

PHYTON

Eric Moraes Ramos
Kurs von Eric Moraes Ramos, aktualisiert more than 1 year ago Beitragende

Beschreibung

2

Modulinformationen

Beschreibung

Class 1
Keine Merkmale angegeben

Beschreibung

Class 2
Keine Merkmale angegeben
What  is a variable? - A container for a value. Behaves as the value that it contains (like maths)   if you want to print your "Hello (your name)": first_name = "Eric" last_name = "Ramos" full_name = first_name + " " + last_name print("Hello" + full_name)   THE RESULT: Hello Eric Ramos   *DO NOT put any quote sign in the variable so you're gonna print it. *if a variable has two words, you must separate them with an underscore sign "_" ---> print(type(name))   if you want to check the data type If you want to comment a line just put the # sign   ------------------------------------------------------------------------------------ INT (INTEGER) ----------------------------------------------------------------------                                                                                                        A Whole Number   age = (a number you want to use)   *DO NOT use any quote marks in variable, otherwise you're gonna transform it in a string ('str'), and you won't be able to "do maths" with it   age = 27 age = age + 1 (if you want to do maths) print(age)   If you want to display your age variable along with a string e.g. Your age is 27   print("Your age is: "+age) WRONG To use a string  and a int value, you must convert your int in a string, using typecasting   THAT'S HOW TO DO IT: print ("Your age is: " +str(age))     ---------------------------------------------------------------------- FLOAT (FLOATING POINT NUMBER) ----------------------------------------------------------------------                                                                                                      A Decimal Number       height = 250.5 #print(height) print("Your height is: "+str(height)+"cm")   THE RESULT: Your height is 250.5cm     -------------------------------------------------------------------------------------- BOOLEAN ----------------------------------------------------------------------------------------------                                                                                                            True or False       human = True #print(human) print("Are you a Human: "+str(human))   THE RESULT: Are you a human: True
Weniger sehen

Beschreibung

Class 3
Keine Merkmale angegeben
#Multiple assignment = Allows us to assign multiple variables at the same time in one line of code   name = "Eric" age = "27" attractive = True print(name) print(age) print(attractive) To avoid repetition of your code, you can do it instead (example below) print(name) print(age) print(attractive)   name, age, attractive = "Eric", 27, True   #----------------------------------------------------------------- In case your variables have the same value Spongebob = 30 Patrick = 30 Sandy = 30 Squidward = 30 *There's no need of doing this, you can opt for this one below     Spongebob = Patrick = Sandy = Squidward = 30 print(Spongebob) print(Patrick) print(Sandy) print(Squidward)
Weniger sehen

Beschreibung

Class 4
Keine Merkmale angegeben
name = "Eric"     print(len(name)) #If you want to check the lenght of your variable   print(name.find("e")) #To find the first index of where this caracter is, imgining we looking for the capital "e", in this case will be at 0, because is where it starts on computers.   print(name.capitalize( )) #It capitalizes the first letter of your string, if you have more than one word, it won't affect the second one.   print(name.upper( )) #This will make your string all uppercase   print(name.lower( )) #This will make your string all lowercase   print(name.isdigit( )) #This will return true/false depending if your string is a digit(number) or not   print(name.isalpha( )) #This will return true/false if your string is alpahabetical characters (if there's space, it's gonna return false)   print(name.count("c")) #If you want to count how many characters are whitin our string   print(name.replace("e", "k")) #When you want to replace characters, first the one to be replaced and then separe with comma   print(name*10) #If you want to display a string multiple times
Weniger sehen

Beschreibung

Class 5
Keine Merkmale angegeben
#Type casting = convert the data type of a value to another data type   x = 1      #integer y = 2.0   #float z = "3"   #string (we cannot perform maths on it)   1-Type that value or variable and surround this with a set of parentheses 2-Pre-save this value/variable with the type of data you'd like to convert to   EXAMPLES -- 'Z' is a string (str) and if you want to convert it into a integer, just type: int(z), the same will be apllied to the other types.
Weniger sehen

Beschreibung

Class 6
Keine Merkmale angegeben
name = input("What is your name?: ") age = int (input("How old are you?: ")) height = float (input("How tall are you?: "))     print("Hello "+name) print("You are " + str(age) + " years old" print("and " + str(height) + "cm tall")   REMEMBER TO CAST TYPE EVERY NECESSARY DATA WHEN PRINTING
Weniger sehen

Beschreibung

Class 7
Keine Merkmale angegeben
import math pi = 3.14 x = 1 y = 2 z = 3   print(round(pi))             #To round the number print(math.ceil(pi))       #To round the number up print(math.floor(pi))    #To round a number down print(abs(pi))                 #To be given the absolute number of a value print(pow(pi,3))             #Will raise your value to a power (in this example is 3.14x3.14) print(math.sqrt(pi))      #To se the "Square root function" print(max(x,y,z))            #This will give you the largest of the values you set print(min(x,y,z))             #This function will give you the lowest
Weniger sehen

Beschreibung

Class 8
Keine Merkmale angegeben
Slicing = create a sub-string by extracting elements from another string indexing[ ] or slicing( ) [start:stop:step]   name = "Eric Ramos" *          first_name = name[ : 3]                       #[0:3] **        last_name = name[5 : ]                        #[5:0] ***      funky_name = name[ : :2]                   #[0:end:2] ****    reversed_name = name[ : :-1]            #[0:end:-1     *If you want to print just the first name, in this case we already know that computers always start at ZERO. **You need to know where your string begins, leave it blanket, the computer will read as the very end of your string. ***Depending on the value you set on "step", you gonna print certain characters (1 is default 'cuz will display the first letters) ****You spell the value backwards, just set the "step" as -1    IF YOU DON'T PUT ANYTHING AT THE BEGINNING, COMPUTERS WILL UINDERSTAND AS ZERO, SO YOU CAN SHORTEN YOUR INDEXING   website1 = "https://google.com.br" website2 = "https://wikipedia.com" Imagine that we want to remove "https://" and just display "google" First we need to create a slice object: slice = slice (  ) within the parentheses we can add up to 3 values (start, stop, step), NOTE THAT THIS TIME YOU SEPARATE THEM WITH COMMA.   EXAMPLE slice1 = slice( 8,-7 ) HOW TO DISPLAY THIS? print ( website1 [slice1] )
Weniger sehen
Zusammenfassung anzeigen Zusammenfassung ausblenden