Skip to content
Chris Kimpton edited this page Jan 22, 2019 · 13 revisions

Python language covered per CodeClub project

  • print('') and multi-line using print(''' ... ''')
  • repeat chars - print('&*' * 10)
  • maths - print(3 - 1)
  • variables - myvar = 1
  • input - myvar = input('What...')
  • convert to int - int(myvar)
  • imports - from random import randint, myvar = randint(1,3)
  • conditional logic, like, note the colons and two space (or tab) indent
  • if myvar == 1:
  • othervar = '2'
  • elif myvar == 2:
  • othervar = '3'
  • else:
  • othervar = '4'
  • from turtle import *
  • moves - forward(100)
  • write(0)
  • loops, like so - remember colon and indents like above
  • for step in range(5):
  • write(step)
  • forward(20)
  • find a char in a string - pos = "123".find('2')
  • modulo - % 5 % 2 => 1
  • lookup char pos in string - "123"[2] => "3"
  • loop chars in string
  • for char in mystring:
  • add to end of string - a='1', b='2', a+=b => a is now '12'

And some useful links

Clone this wiki locally