forked from a-newman/python-tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2_variables.py
More file actions
47 lines (42 loc) · 1.54 KB
/
2_variables.py
File metadata and controls
47 lines (42 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# ** Variables **
#
# A variable is a way of storing a piece of data or information for reuse. In
# Python, variables are assigned using the equals sign `=`. For example, the
# following line:
x = 1
# assigns the value 1 to the variable x.
#
# When a variable name is multiple words long, the words are separated with
# underscores, like so:
my_long_variable_name = 1
# ** Data types **
#
# In Python, variables can contain many different types of data. Here are some
# examples.
#
# An integer is a whole number.
my_integer = 1
# A float is a number with a decimal point.
my_float = 1.1
# A string is a piece of text. Strings are surrounded by either single or
# double quotes.
my_string = "Hello, world!"
my_other_string = 'Hello, students!'
# A boolean is a special data type that can take on only one of two binary
# values: True or False
my_positive_boolean = True
my_negative_boolean = False
# ** Exercises **
# 1. Variables can be reused. On line 38, set y to a new value. Then run
# the code to see the output. Note: you can print multiple things at once
# by separating them with a comma!
y = 0
print("y =", y)
# Your code here (give y a new value)
print("y is different now!")
print("y =", y)
# 2. What happens when you have an error in your code? Let's find out!
# Uncomment the line below and see what happens.
#print(Oops, I tried to print a string without parentheses!)
# Inspect the error message closely. What information does it give you?
# Learning how to read error messages will be important for debugging later!