Python Syntax

Lesson 01/13 – Welcome!

[code lang=”python”]
print "Welcome to Python!"
[/code]

Lesson 02/13 – Variables

[code lang=”python”]

Write your code below!

my_variable = 10
[/code]

Lesson 03/13 – Booleans

[code lang=”python”]

Set the variables to the values listed in the instructions!

my_int = 7
my_float = 1.23
my_bool = True
[/code]

Lesson 04/13 – You’ve Been Reassigned

[code lang=”python”]

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
[/code]

Lesson 05/13 – Whitespace

[code lang=”python”]
def spam():
eggs = 12
return eggs
        
print spam()
[/code]

Lesson 06/13 – Whitespace Means Right Space

[code lang=”python”]
def spam():
    eggs = 12
    return eggs
        
print spam()
[/code]

Lesson 07/13 – A Matter of Interpretation

[code lang=”python”]
spam = True
eggs = False
[/code]

Lesson 08/13 – Single Line Comments

[code lang=”python”]

this is a comment

mysterious_variable = 42
[/code]

Lesson 09/13 – Multi-Line Comments

[code lang=”python”]
"""Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce arcu arcu, vehicula id urna eget, mollis ullamcorper eros. Nullam felis risus, iaculis sed ipsum quis, interdum mollis lacus. Phasellus efficitur magna commodo augue porta, ac sodales magna tempus. Sed mollis sagittis lacus, vel sodales dolor blandit eu. Quisque eu ex lorem. Duis sit amet leo eu sapien porta molestie. Praesent sed tristique diam. Maecenas venenatis, enim nec molestie imperdiet, lacus urna condimentum ex, sit amet posuere eros tellus pharetra sapien. Phasellus nec felis pretium, hendrerit magna ac, dignissim nibh. Sed nec cursus dui. Nunc ac justo accumsan, tristique tortor vitae, suscipit velit. In rutrum, mauris non fermentum semper, lectus risus blandit dolor, quis iaculis justo tellus id nulla. Nam malesuada pellentesque leo, eu sollicitudin eros vestibulum at. Curabitur sit amet luctus eros, eu dapibus magna.
"""
[/code]

Lesson 10/13 – Math

[code lang=”python”]

Set count_to equal to the sum of two big numbers

count_to = 1234 + 1234

print count_to
[/code]

Lesson 11/13 – Exponentiation

[code lang=”python”]

Set eggs equal to 100 using exponentiation on line 3!

eggs = 100 ** 1

print eggs
[/code]

Lesson 12/13 – Modulo

[code lang=”python”]

Set spam equal to 1 using modulo on line 3!

spam = 5 % 4

print spam
[/code]

Lesson 13/13 – Bringing It All Together

[code lang=”python”]

this is a comment

monty = True
python = 1.234
monty_python = python ** 2
[/code]

Leave a Reply

Your email address will not be published. Required fields are marked *

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four 
    spaces will be stripped off, but all other whitespace
    will be preserved.
    
    Markdown is turned off in code blocks:
     [This is not a link](http://example.com)

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see http://daringfireball.net/projects/markdown/syntax