Skip to content

Commit 33210c7

Browse files
authored
Add files via upload
0 parents  commit 33210c7

11 files changed

+362
-0
lines changed

10. basic Functions intro.py

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
'''
2+
Hello everyone and welcome to another python 3 basics video. In this video we
3+
will be discussing the basics of a function.
4+
5+
The idea of a function is to assign a set of code, and possibly variables,
6+
known as parameters, to a single bit of text. You can think of it a lot like
7+
why you choose to write and save a program, rather than writing out the
8+
entire program every time you want to execute it.
9+
'''
10+
11+
# To begin a function, the keyword 'def' is used to notify
12+
# python of the impending function definition, which is what def
13+
# stands for.
14+
15+
# from there, you type out the name you want to call your function.
16+
# it is important to choose a unique name, and also one that wont conflict
17+
# with any other functions you might be using. For example, you wouldn't
18+
# want to go calling your function print.
19+
20+
21+
# so here we've called our function example. After the name of the function,
22+
# you specify any parameters of that function within the parenthesis
23+
# parameters act as variables within the function, they are not necessary
24+
# to create a function, so first let's just do this without any parameters.
25+
26+
def example():
27+
# functions just run whatever code is encased with them.
28+
print('this code will run')
29+
z = 3 + 9
30+
print(z)
31+
32+
# now if we just run this, we see nothing happens. We have to actually call
33+
# this function to execute, because all we've done so far is just define the
34+
# function and what it does. To run it, you can either type out the function in
35+
# the console like so:
36+
37+
# or you can add it to the actual script itself:
38+
39+
example()
40+

11. Function Parameters.py

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
'''
2+
Welcome to another python 3 basics video, in this video we will carryon with
3+
functions. In the last video you were shown a very basic function, without
4+
any parameters
5+
6+
In this video, lets include a parameter, and give this function more...
7+
functionality.
8+
'''
9+
10+
11+
# changed name to simple math, to better describe our intentions
12+
'''
13+
Now we've specified 2 parameters for our function, calling them num1
14+
and num2, for number 1 and number 2.
15+
16+
Now, we carry on writing our function, where we can specify what we
17+
desire to do with num1 and num2.
18+
19+
in our case, we want to do simple addition.
20+
'''
21+
def simple_addition(num1,num2):
22+
answer = num1 + num2
23+
print('num1 is', num1)
24+
# so here the answer variable will be filled with whatever
25+
# num 1 plus num 2 is.
26+
print(answer)
27+
# then at the end, we want to print out the answer to the client
28+
29+
30+
'''
31+
so now we run this, and when we want to do some simple_addition...
32+
'''
33+
34+
simple_addition(5,3)
35+
# here we will do 5 + 3, for an answer of 8
36+
37+
'''
38+
There is no limit to the amount of variables you can have. The only thing
39+
you will want to look out for at this point is the order of the variables,
40+
41+
as well as the quantity.
42+
43+
You can protect yourself from order by doing the following in your calling:
44+
'''
45+
46+
simple_addition(num1=3,num2=5)
47+
# or more clearly #
48+
simple_addition(num2=3,num1=5)
49+
50+
# in this case, if you are clear in your specification, it does not matter
51+
# the order. Most people, however, do not write out the variables like that,
52+
# they just maintain the order.
53+
54+
55+
#finally, it is important to use the proper quantity of variables.
56+
57+
# will not work, too many vars
58+
simple_addition(3,5,6)
59+
60+
# will not work, too few vars
61+
simple_addition(3)
62+
63+
64+
65+
66+
'''
67+
That's it for this video, in the next video I willbe covering default variable
68+
assignments.
69+
70+
'''
71+
72+
73+
74+
75+
76+

12. Function Parameter Defaults.py

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
'''
2+
Hello again and welcome to another python 3 basics video. In this video we
3+
will be covering default function parameters
4+
'''
5+
6+
# so normally, you write a function like so:
7+
def simple(num1,num2):
8+
pass
9+
10+
# What you can do, however is:
11+
12+
def simple(num1, num2=5):
13+
# what this does is specify a "default parameter" just in case
14+
# one is not specified.
15+
# this is useful so all parameters dont need to be called
16+
# every single time. Generally, this is used for modules.
17+
# an example would be a module that makes windows for users.
18+
pass
19+
20+
21+
# so here, the user must specifiy width and height, but a font of times
22+
# new roman, for example, is the default so they dont have to say that
23+
# every single time.
24+
25+
def basic_window(width,height,font='TNR'):
26+
# let us just print out everything
27+
print(width,height,font)
28+
29+
30+
31+
# now, when we call basic_window, we can break a rule we established
32+
# earlier:
33+
34+
# see, only two parameters, when we require 3
35+
basic_window(350,500)
36+
37+
# we can do this because there is a default if font is not specified. Should
38+
# a user wish to specify however, they can do
39+
40+
basic_window(350,500,font='courier')
41+
42+
# here, it is just important that you place any parameters with default values
43+
# at the very end, to avoid trouble when calling the function down the road.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
print('This is an example of the print function')
2+
3+
# while we are here, let's talk a bit about strings #
4+
5+
print("double quotes")
6+
7+
print('or single...')
8+
9+
print('concatena'+'tion')
10+
11+
print('can do this',5)
12+
#print('cannot do this:'+5)
13+
14+
#print('Can't do this')
15+
print('you\'ll have success here')
16+
print("you'll have sucess here too")
17+
18+
19+
20+
'''
21+
These are just the basics of strings for now, you can also pass
22+
variables and do all sorts of neat things.
23+
'''

3. simple maths.py

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
1+3
2+
4*4
3+
5-2
4+
5/2
5+
6+
7+
8+
#exponents
9+
4**4
10+
11+
4.5*2
12+
13+
#Integers whole numbers
14+
15+

4. variables.py

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
'''
2+
Hello and welcome to my variables tutorial video. In this video I will teach
3+
you about variables, which you will quickly find yourself using extremely
4+
frequently.
5+
6+
Variables act as a placeholder for whatever you place in them, and, can be
7+
changed... so they are... you guessed it... VARIABLE!
8+
'''
9+
10+
11+
exampleVar = 55
12+
print(exampleVar)
13+
14+
#cannotDo = Hey!
15+
16+
canDo = 'Hey!'
17+
print(canDo)
18+
19+
canContainOperations = 5/4
20+
print(canContainOperations)
21+
22+
#canEvenContainFunctions = # but more on that later....

5. while loop.py

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
2+
3+
condition = 1
4+
5+
while condition < 10:
6+
print(condition)
7+
condition += 1
8+
9+
10+
condition = '2'
11+
12+
while condition > 5:
13+
print 'test'
14+
15+
# Another favorite of many people... the infinite loop #
16+
17+
while True:
18+
print('doing stuff!!')
19+
20+
21+
22+
# control+c to break script!
23+
24+
25+
26+
27+
28+

6. for loop.py

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#! python3
2+
3+
'''
4+
Hey everyone and welcome to another python 3 tutorial. This tutorial will be
5+
covering the for loop. The for loop is used for many of the same tasks as the
6+
while loop.
7+
8+
Typically, you will see the while loop being used for finite tasks that have
9+
predetermined length, and the for loop being used for tasks that have uncertain
10+
and variable timeframes.
11+
12+
That said, the for loop can be used for the exact same tasks as the while loop.
13+
14+
for this reason, I prefer the for loop myself, but again, it comes down to
15+
personal preference. I will show you why here.
16+
17+
'''
18+
import time
19+
20+
exampleList = [1,5,6,6,2,1,5,2,1,4]
21+
22+
for x in exampleList:
23+
print(x)
24+
25+
26+
27+
# usually people use for loops to iterate through something,
28+
# and you can iterate for the same purposes as the previous
29+
# while loop did, as more of a counter:
30+
31+
32+
for x in range(1,11):
33+
print(x)
34+
35+
36+
# Range is a built in python function, and it literally will make a range
37+
# of numbers for you. In python 2.7, Python's 3.3 is the equivalent of
38+
# 2.7's xrange... so this range is a generator function and will not
39+
# blow out your memory like python 2.7's range.
40+
41+
time.sleep(555)

7. if statement.py

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
x = 5
2+
y = 10
3+
z = 22
4+
5+
if x > y:
6+
print('x is greater than y')
7+
elif x == z:
8+
print('x is less than z')
9+
elif 5 == 2:
10+
print('5 is greater than 2')
11+
else:
12+
print('if and elif(s) never ran')

8. if else.py

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
'''
2+
3+
hello everyone and welcome to my if else basics tutorial.
4+
5+
The idea of the if else pairing is to add 1 more layer of logic to the
6+
usage of your if statement here. The else statement can actually be used
7+
in quite a few other ways, like with while, for, and except.
8+
9+
Here, the idea is to ask if something is the case, like we did before...
10+
... and, if it is not the case, then do something else. In this case,
11+
12+
we will just print something basic.
13+
14+
15+
'''
16+
17+
18+
x = 5
19+
y = 8
20+
21+
if x < y:
22+
print('x is greater than y')
23+
if x > 55:
24+
print('x is greater than 55')
25+
else:
26+
print('x is not greater than y or 55')
27+

9. if elif else.py

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
'''
2+
What is going on everyone welcome to my if elif else tutorial video.
3+
4+
The idea of this is to add yet another layer of logic to the pre-existing if else statement.
5+
6+
See with our typical if else statment, the if will be checked for sure, and the
7+
8+
else will only run if the if fails... but then what if you want to check multiple ifs?
9+
10+
You could just write them all in, though this is somewhat improper. If you actually desire to check every single if statement, then this is fine.
11+
12+
There is nothing wrong with writing multiple ifs... if they are necessary to run, otherwise you shouldn't really do this.
13+
14+
Instead, you can use what is called the "elif" here in python... which is short for "else if"
15+
16+
17+
'''
18+
19+
x = 5
20+
21+
y = 10
22+
23+
z = 22
24+
25+
# first run the default like this, then
26+
# change the x > y to x < y...
27+
28+
# then change both of these to an ==
29+
if x > y:
30+
print('x is greater than y')
31+
elif x < z:
32+
print('x is less than z')
33+
34+
else:
35+
print('if and elif never ran...')

0 commit comments

Comments
 (0)