VARIABLES & STRINGS:
Variables are used to store
values. A string is a series of characters, surrounded by single or double
quotes.
|
Hello
world
|
print("Hello
world!")
|
Hello
world with a variable
|
msg = "Hello world!" print(msg)
|
Concatenation
(combining strings)
|
first_name = 'albert' last_name = 'einstein'
full_name =
first_name + ' ' + last_name print(full_name)
|
LISTS:
A list stores a series of items
in a particular order. You access items using an index, or within a loop.
|
Make
a list
|
bikes =
['trek', 'redline', 'giant']
|
Get the first item in a
list
|
first_bike =
bikes[0]
|
Get
the last item in a list
|
last_bike =
bikes[-1]
|
Looping
through a list
|
for bike in bikes: print(bike)
|
Adding
items to a list
|
bikes = [] bikes.append('trek') bikes.append('redline')
bikes.append('giant')
|
Making
numerical lists
|
squares = []
for x in range(1, 11): squares.append(x**2)
|
The Learning Plarform
Comments
Post a Comment