Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

warm up #12

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 41 additions & 1 deletion python_sandbox_starter/dictionaries.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,42 @@
# A Dictionary is a collection which is unordered, changeable and indexed. No duplicate members.
# A Dictionary is a collection which is unordered, changeable and indexed. No duplicate members.
# Read more about dictionaries at https://docs.python.org/3/tutorial/datastructures.html#dictionaries

#
person = {
'first_name': 'John',
'last_name': 'Doe',
'age': 30
}

print(person, type(person))
# get vlaue
print(person['first_name'])
print(person.get('last_name'))

# add key value
person['phone'] = '34343434'

# get dict key
print(person.keys())

# remove item

del person['age']
person.pop('phone')

# clear
# person.clear()

# legnth
print(len(person))

# list of dict
people = [
{'name': 'niko', 'age': 5},
{'name': 'yan', 'age': 54},
]

print(people[0]['name'])



20 changes: 19 additions & 1 deletion python_sandbox_starter/functions.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,25 @@
# A function is a block of code which only runs when it is called. In Python, we do not use parentheses and curly brackets, we use indentation with tabs or spaces

# Create a function
def sayHello(name):
print(f'Hello {name} !')

def sayHelloSam(name='Sam'):
print(f'Hello to you to {name}')

# A lambda function is a small anonymous function.
sayHello('Nikolas')
sayHelloSam()

# return values
def getSum(num1, num2):
total = num1 + num2
return total

print(getSum(3,5))


# A lambda function is a small anonymous function.
value = lambda n1, n2: n1 + n2
print(value(2,3))
# A lambda function can take any number of arguments, but can only have one expression. Very similar to JS arrow functions

32 changes: 32 additions & 0 deletions python_sandbox_starter/lists.py
Original file line number Diff line number Diff line change
@@ -1 +1,33 @@
# A List is a collection which is ordered and changeable. Allows duplicate members.

# create a list
numbers = [1,2,3,4,5]
fruits = ['apples', 'oranges', 'grapes']

# use constructor
# numbers2 = list((1,2,3,4,5))

# print(numbers, numbers2)

# get a value
print(fruits[1])
# get length
print(len(fruits))
# append
fruits.append("mangos")
# remove
fruits.remove("apples")
# insert
fruits.insert(2, "papaya")
# Remove with pop
fruits.pop(2)
# reverse
fruits.reverse()
# sort
fruits.sort()
# reverse sort
fruits.sort(reverse=True)
# change value
fruits[0] = 'bananas'

print(fruits)
16 changes: 16 additions & 0 deletions python_sandbox_starter/strings.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
# Strings in python are surrounded by either single or double quotation marks. Let's look at string formatting and some string methods

name = "Nikolas"
age = 32

#concatenate
# print('Hello i am ' + name + 'I am ' + str(age))

# String Formatting

# arguments by position
# print('Mt name is {name} and i am {age}'.format(name=name, age=age))

#F-Strings (3.6+)
# print(f'Hello, my name is {name} and i am {age}')

# String Methods

s = 'hello kitty'

# capitalizy
print(s.find("e"))
23 changes: 23 additions & 0 deletions python_sandbox_starter/tuples_sets.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,28 @@
# A Tuple is a collection which is ordered and unchangeable. Allows duplicate members.

# create a tuple
fruits = ('Apples', 'Oranges', 'Grapes')
fruits2 = 'Mango'

# delete
# del fruits2

print(fruits)
print(fruits2)


# A Set is a collection which is unordered and unindexed. No duplicate members.

# create a set
fruits_set = {'Apples', 'Orange', 'Mango'}
# check if in set
print('Apples' in fruits_set)
# Add to set
fruits_set.add('papaya')
print(fruits_set)
# remove
fruits_set.remove('papaya')
print(fruits_set)
# clear set
fruits_set.clear()
print(fruits_set)
22 changes: 21 additions & 1 deletion python_sandbox_starter/variables.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# A variable is a container for a value, which can be of various types

'''
This is a
Expand All @@ -13,3 +12,24 @@
- Must start with a letter or an underscore
- Can have numbers but can not start with one
"""
# x = 1 #int
# y = 2.5 #float
# name = "John" #string
# is_cool = True #bool

#multi assigment

x, y, name, is_cool = (1, 2.5, "john", True)

print("Hello")

# basic math
a = x + y

# Casting

x = str(x)
y = int(y)
z = float(y)

print(type(z), z)