Written lessons for python 3.4 off buckys vids

+9 Isaiah Rahmany · August 30, 2014
Well guys it's gonna take a while to catch up but I finally got lesson 2 of his python 3.4 tutorials

lesson2:


# For those new to python, there are many simple operators you will
# need to learn. Now I assume that you know how to do addition and subtraction.
# For ex: 3+4 or 4-3, fairly easy right? Now when it comes to multiplication
# you use the asterisk key * and for division it's the forward slash /
# Now if you run this we will put it to the test.

print("Part1:")
print("4 + 16 = ", 4+16)
print("16 - 4 = ", 16-4)
print("2 * 2 = ", 2*2)
print("2 / 2 = ", 2/2)
print("")

# Also python does follow the order of operations so if I put 8 + 10 * 2
# you would think I would get 36 right? Well, no I wouldn't actually I would
# get 28 because what it's doing here is following PEMDAS as in:

#1.Parentheses
#2.Exponents
#3.Multiply
#4.Divide
#5.Addition
#6.Subtraction

# Also if you want to divide and take your answer and round it down to the
# Nearest whole number you simply type //  for example if I type 18//4 I get
# The number 4 as to where if I type 18/4 I get 4.5 see it rounds it down
# and to do a number to the power of something its simply 2 asterisks **

print("Part2:")
print("18 // 4 = ",18//4)
print("18 / 4 = ",18/4)
print("2 ** 2 = ",2**2)
print("")

# ALSO! I almost forgot modulus which I don't know what the hell it is but I
# Do know what it does it gives you the remainder of a division equation.
# The key for it is % or percentage sign... for example 8%3 would equal 2
# Because 8 / 3 has a remainder of 2

print("Part3:")
print("8 % 3 = ",8%3)
print("")

# Also we have variables like if you type: isaiah = 14 and then type
# print(isaiah) you will see the number 14

print("Part4:")
isaiah = 14
print(isaiah)

# That concludes lesson 2

lesson 3:


# Strings guys it's all about string's in this tutorial!
# So what are strings? Well it's the coding term for a line of text.
# That's right I know it sounds dumb but it is what it is...
# So how do I make a string? The same way you made a variable, but
# You need to add quotes for ex: me = "Isaiah Rahmany"
# now if I type: print(me), it will print my name! Cool, right?
# But you can use single quotes too but there's a problem and here's why.
# Those quotes define where to start and end the string so what if I wanted
# a quote inside my string like quote = "isaiah said,"This is awesome.""
# now well python will be like what the hell are you doing?
# So what I would do is this: quote = 'isaiah said,"Now it should work!"'
# notice that since I used single quotes to start insted it was looking for a
# single quote to end with so thats why I didn't get and error
# look:

print("Part1:")
quote = 'isaiah said,"it worked"'
print(quote)
print("")

# Also lets say I have to use singlequotes and double quotes inside the same
# string, so here's our string: quote = 'isaiah said,"that's what she said"'
# now as you can see in the word that's it would stop and the last word would
# be: that, so what you'll need to do is use something called an escape
# character which is the back slash \ so if you want it to continue reading the string
# You would type quote = 'isaiah said,"that\'s what she said"' and look Ill even print
# It so that when you run it you can see it worked.

quote = 'isaiah said,"that\'s what she said"'
print("Part2:")
print(quote)
print("")

# so backslash anything inside the string according to python means
# treat that as part of the string...

# also you have have noticed that i have been using a function called print()
# what this fuction does it print text on the screen as you can see it's what
# I used to print text on the screen when you run the program
# So how to use it is type print("text goes here") or you can print a string
# for ex: name = 'isaiah' print(isaiah)
# you can also print a variable, for ex:

print("Part3:")
a = 2+3
print(a)
print("")

# also you can print a string and a number or number and a string like this
# ex:

print("Part4:")
name = ' isaiah rahmany '
age = 14
print(name, age)
print(age, name)
print("")

# Notice the comma normally to put together to strings you type: print(name + age)
# But since age is a variable you must join them with a comma why I don't know
# I know it's stupid but I don't make the rules they do...
# Also almost forgot if you want to move all the text after a certain point to
# A new line then type \n somewhere in your text and all text after that \n will
# Be moved to a new line

# Now bucky in his tutorial brings me to something I totaly never thought of
# So here it is, if I type print('C:\users\isaiah\desktop\newfolder')
# I am gonna get this :

print("Part5:")
print('C:\users\isaiah\desktop\newfolder')
print("")

# The reason you get C:\users\isaiah\desktop
# ewfolder is because it read \newfolder as \n ewfolder notice the \n it though
# I meant new line The way you fix this is simply type: print(r'C:\users\isaiah\desktop\newfolder')
# The r tells it to simply print the raw string

# And I covered this but I'll say it again if you add together strings with the + sign
# It combines the strings for ex:

print("Part6:")
firstname = 'isaiah '
lastname = 'rahmany'
print(firstname + lastname)
print("")

# Also to finish up you can multiply string's and what I mean by this is

print(30 * "*")

# What this would do is print an asterisk 30 times accross the same line

# so I hope you get the Idea I am sorry I am so slow on the tutorials I can't
# type so it takes a while :P but that's all for this tutorial

in part 5 you actually will get a unicode error I think but yea still to fix it make it a raw string...

lesson 4:


# Hello and welcome back guys today were going over more crap
# on strings I know sounds boring but trust me it's the fun
# stuff today we're gonna be slicing strings! Now you're
# probably like wtf is slicing strings Isaiah? Well
# Here's an example

print("Part1:")
ham = "I like ham"
print("the first char in the string ham is -> " + ham[0])
print("")

# and what I did there is I took the first character from ham and printed it
# now I know you're probably like what the hell? Why did he put zero? Well leme tell you why,
# when counting computers start from zero so the first char is 0 second is 1
# third is 2 etc. But how did I grab that first char? well you type the string name
# then [] and between those brackets the position of the char you want to take like 0 for pos 1.
# or I can do print(ham[0:10]) and this will print the first 11 characters in a sequence.

print("Part2:")
print(ham[0:10])
print("")

# now it goes left to right but what if I want right to left? No worries bud I got you
# covered simply do ham[-1] and so on to start from the right if you type ham[-1] it
# will always give you the last letter or number or whatever...
# also another function called len() will get you the length of a list or sting or tuple
# for ex:

print("Part3:")
print("The length of ham is -> ", len(ham))

# also spaces count as characters and again length gives you the number
# of characters in a string and for a list or tuple or dictionary, the number of items
# Thats all for this tutorial have a good one...



lesson 5:


# Today's tutorial is on lists and I am only gonna be
# referencing things from now on as little side notes
# Only because it's a bit hard to explain everything in depth

items1 = ['isaiah', 'rahmany']
print(items1[0] + " " + items1[1])

# what this does is make a list with 2 items the list name is called items
# and to print an item from the list you type print(items[0])
# where I put that zero is where you put the item number

items2 = [14, 'isaiah rahmany']

# this list has 2 different types of items so yes you can put integers and floats and doubles
# inside of lists as items alongside strings

print(len(items1 + items2))

# this prints the number of items total of those 2 lists combined

items2.append('age:')

# Adds an item with value of 14 to items2 as you can see

print(items2)

items2[1]='Bucky Roberts'
print(items2[1])

# changes items2[1] to bucky roberts as you can see

print(items2[:])

# prints everything in items2

items2.remove(items2[2])

# deletes the 3rd or last item from the list items2

items2[:2] = [14, 'isaiah rahmany']

# changes items 1 and 2 so that 1 = 14 and 2 = 'isaiah rahmany'

print(items2)

# prints the first 2 items from the list


# sorry that I am no longer going in depth
# I am just going to sum up what we've learned
# in each tutorial to make things easier
# So yea, thank you for reading.
# Have a nice day!




and btw in lesson 5 if you did this to delete an Item off the list I got this when I did it idk about
you?

items2 = [14, 'isaiah rahmany', 'age:']
items2[2] = []

so i fixed it by doing this:

items2.remove(items2[2])

Post a Reply

Replies

Oldest  Newest  Rating
+2 Maria Scuilli · August 30, 2014
This is very helpful, thank you!
+1 Isaiah Rahmany · August 30, 2014
Thank you !
+3 Jake Scaife · August 30, 2014
This is great! The bit about modulus made me laugh ;) I need to watch the python series but I can't seem to find the time.
+2 Kaveh Greenwood · September 1, 2014
Thank you so much for this. It is much appreciated.
+1 Wei Zeng · September 3, 2014
awesome!
0 Barbie Banks · February 25, 2015
Great Summarization .... now can you tell me how to read in a Directory... I don't think a simple read statement will do or will it...
0 Abdullah Nauman · February 25, 2015
This is great!
0 SCOTT BUSINGE · March 3, 2015
so helpful!! thanks
  • 1

Python

107,132 followers
About

This section is all about snakes! Just kidding.

Links
Moderators
Bucky Roberts Administrator