-
-
Save azamsharp/31e1f346b213055887cab922f9da4c93 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Data Types in Python | |
# String - Combination of alphanumeric characters 33AAA$%^ | |
# Int - Numbers without decimal (whole numbers) 34, 2,1 100, 986 | |
# Float - Numbers with decimal 5.23, 3.142, 5.0 | |
# Bool - YES/NO, TRUE/FALSE, 1/0, ON/OFF | |
# Variables | |
name = "John" | |
age = 34 | |
pi = 3.142 | |
is_open = True # Snake casing | |
# Python uses snake casing | |
# JS, Swift, Java, Dart, C# uses Camel Casing | |
# Don't use Python Language reserve words as your variable names | |
first_name = "John" | |
last_name = "Doe" | |
# Immutability - String are immutable/ They cannot be changed | |
#print(first_name + last_name + "22" + "aa" + "cc" + "dd" + "ff") | |
company = "DigitalCrafts" | |
cohort = "Feb 2021" | |
#message = "Welcome to " + company + " " + "Cohort " + cohort | |
message = f"Welcome to {company} and cohort is {cohort}" | |
print(message) | |
# Asking for user input | |
# input function always returns you as a String datatype | |
full_name = input("Please enter your full name: ") | |
car_make = input("Enter make of your car: ") | |
car_model = input("Enter model of your car: ") | |
print(full_name) | |
print(car_make) | |
print(car_model) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
first_name = "John" | |
last_name = "Doe" | |
customer_id = "123456" | |
#display_user() # Result in an error because the function does not exists | |
# Functions should be small. They should be reusable | |
# Functions should ONLY DO ONE AND ONE THING ONLY | |
def display_user(): | |
print(f"*******{customer_id}********") | |
print(f"My first name is {first_name} and last name is {last_name}") | |
print("***********************") | |
print("I am not part of the display_user function") | |
display_user() | |
print("code ...") | |
print("some more code ....") | |
display_user() | |
#print("***********************") | |
#print(f"My first name is {first_name} and last name is {last_name}") | |
#print("***********************") | |
#name is a local variable and available only inside the function | |
def greet(name,age): | |
print(f"Hello {name} and my age is {age}") | |
greet("Mary",34) | |
greet("Alex",56) | |
greet("John",67) | |
# causes an error because age is declared inside the greet function | |
#print(age) | |
# A good function is a function with NO arguments | |
def calculate_overdraft_fee(amount): | |
return amount * 0.10 | |
print("Not executed") | |
overdraft_fee = calculate_overdraft_fee(100) | |
if overdraft_fee > 20: | |
print("lock the account") | |
def add(no1, no2): | |
return no1 + no2 | |
result = add(2,3) | |
print(result) | |
# TUPLE | |
def airportNameAndCode(address): | |
return ("Intercontinental Airport", "IAH") # tuple | |
# lines is ignored because it is after the first return | |
return "IAH" | |
print("Ignored...") | |
(airport_name, airport_code) = airportNameAndCode("1200 Richmond Ave") | |
# Optional Arguments | |
def greet_with_optional_age(name, age = 32): | |
print(name) | |
print(age) | |
greet_with_optional_age("Alex Doe", 65) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment