Python Syntax

I) VARIABLES AND DATA TYPES 

i. Welcome! 1/13

print “Welcome to Python!”

> Simply click on Save and Submit code.

ii. Variables 2/13

# Write your code below!
my_variable=10

iii. Booleans 3/13

# Set the variables to the values listed in the instructions!
my_int = 7
my_float = 1.23
my_bool = True

iv. You’ve been reassigned 4/13

# my_int is set to 7 below. What do you think
# will happen if we reset it to 3 and print the result?

my_int = 7

# Change the value of my_int to 3 on line 8!

my_int = 3

# Here’s some code that will print my_int to the console:
# The print keyword will be covered in detail soon!

print my_int


II) WHITESPACE AND STATEMENTS

i. Whitespace 5/13

def spam():
eggs = 12
return eggs

print spam()

ii. Whitespace means right space 6/13

def spam():
eggs = 12
return eggs

print spam()

iii. A matter of interpretation 7/13

spam = True
eggs = False


III) COMMENTS

i. Single line comments 8/13

#We can generate mysterious variables too!

mysterious_variable = 42

ii. Multi-line comments 9/13

“””My netbook is too small for programming and its become old too. I really need to change it”””

> Type whatever you feel like within triple quotes and Save and Submit code.


IV) MATH OPERATIONS

i. Math 10/13

# Set count_to equal to the sum of two big numbers
count_to = 56789043563636738638 + 6545476374252

print count_to

ii. Exponentiation 11/13

#Set eggs equal to 100 using exponentiation on line 3!

eggs = 10**2

print eggs

iii. Modulo 12/13

#Set spam equal to 1 using modulo on line 3!

spam = 5 % 2

print spam


V) REVIEW

Bringing it all together 13/13

# I am learning Python.Thanks to codecademy!
monty = True
python = 1.234
monty_python = python**2


Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s