Skip to content

Instantly share code, notes, and snippets.

@jonathanjouty
Created October 15, 2016 08:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonathanjouty/eb670c8fa071268f36d1212f8bae4283 to your computer and use it in GitHub Desktop.
Save jonathanjouty/eb670c8fa071268f36d1212f8bae4283 to your computer and use it in GitHub Desktop.

Lesson 3

Previously

  1. Basic types (int, float, complex, bool)
  2. Container types (str, list, dict)
  3. Control flow: for/range and if/elif/else

Some things to remember:

  • Implicit type casting (3 / 2 == 1 vs. 3 / 2.0 == 1.5) can happen!
  • Strings are wrapped in quotes, either double " or single '
  • You can concatenate strings with +
  • You can add numbers with +

Wait! What's happening here?

The + operator is polymorphic. For things of type int or float it is addition. For things of type str it concatenates them (i.e. "adds" them).

Back to things to remember:

  • for i in range(10):
  • i is bound to the element for each loop
  • range(x) is a function that creates a list
  • if(condition1 and condition2):
  • Remember to add the : at the end
  • Indentation!

e.g.

for i in range(100):
  if(i % 2 == 0 and i % 3 == 0):
    print('FizzBuzz')
  elif(i % 2 == 0):
    print('Fizz')
  elif(i % 3 == 0):
    print('Buzz')
  else:
    print(i)

This time: more control flow!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment