Skip to content

AlexandreFPGoncalves/One-Week-Python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Project Resume


Integers and Floats
File: Section3_PythonNumbers/integersAndFloats.py
  • Integers are numbers with no decimal houses like the following examples
  • While Floats may be rounded but always have a decimal house
  • The method type() is used to reveal the type of the argument used
type(5)     //<class "int">
type(5.0)   //<class "float">

Basic Operators
File: Section3_PythonNumbers/basicOperators.py
  • If you calculate an integer and a float the answer will always be a float
print("Type of 12 + 1.5",type(12+1.5))    #Type of 12 + 1.5 <class 'float'>
Integer Division
  • It rounds down the result
print("10 / 3 = ", 10 / 3, " | 10 // 3 = ", 10 // 3)    
#10 / 3 =  3.3333333333333335 | 10 // 3 =  3
Exponentiation
print("8 ** 3 = ", 8 ** 3)    
#8 ** 3 =  512
Modulo
  • Remainder of the operation
print(38 % 10) 
# 10 goes into 38... 3 times, with a remainder of 8
Basic Operators
len
  • length of a string
name = "Alex"
len(name) #4
input
  • Inputs a question to the user and can be captured in a variable
first_name = input("What is your name?")
print("So your name is " + first_name+ "!")
#So your name is XXX!
Casting Typess
  • They change the variable type, int will chop the float decimal off
age = input("How old are you?")
doubled_age = int(age) * 2
print("if we multiplied your age by 2 it would be: " + str(doubled_age))
#How old are you?20
#if we multiplied your age by 2 it would be: 40
FStrings
  • f strings will read and evaluate and code between {} the result will be turned into a string and inserted into the overall string
age_in_days = input("How old are you? (in days (years*365))")
print(f"You are {float(age_in_days) / 365} old!")
#How old are you? (in days (years*365))7665
#You are 21.0 old!
Comparison Operators
Comparing Floats and Ints
  • if you compare float and ints they represent the same value
print(4.00000 == 4)
#True
print(4.00001 == 4)
#False
The "in" Operator
  • The "in" operator looks to see if an items is a member of a sequence.
"a" in "cat"
#True
Generate random int
from random import randint
print(randint(1,6))
Range function
  • Start is included, Stop is excluded
  • Yo may not provide the starting point so the range will start at 0
#range(1,10,2) #Start, Stop and Step
for num in range(5,10):
    print(num)
#5,6,7,8,9

About

One Week Python Udemy Course from Colt Steele

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages