Welcome to the first chapter of our Python tutorial for beginners using Bible stories! In this chapter, we'll explore the story of creation and learn about variables and basic data types in Python.
In programming, we often need to store and manipulate information. One way to do this is by using variables. A variable is like a container that can hold a value. We can give each variable a name, and then use that name to refer to the value stored in the container. To create a variable, we assign a value to a name using =
.
For example, in the creation story, we can use variables to represent different elements of creation. Here's how we might create variables for the first three days of creation:
day1 = "Light"
day2 = "Sky"
day3 = "Land"
In this example, we made three variables named day1
, day2
, and day3
. Each variable stores a value that represents a part of creation from the first three days. Once you have created the variables, use the print()
function to display their values. Here's an example of how to print the value of a variable:
day1 = "Light"
print(day1) # Output: Light
<aside> 💡 Did You Know?
In this chapter, we are using two functions called print()
and type()
. Functions are like little helpers in programming that perform specific tasks. We will learn more about functions in Chapter 4, but for now, just remember:
print()
: This function helps us display the value of a variable or a message on the screen. For example, print(day1)
will show the value of the day1
variable.type()
: This function helps us find out the data type of a variable. It tells us whether a variable is a string, integer, or floating number. For example, type(day1)
will return the data type of the day1
variable.Don't worry if you don't understand everything about functions yet. We will dive deeper into the concept in Chapter 4!
</aside>
In Python, there are several basic data types that we can assign to a variable, including:
str
: represent strings or texts and are enclosed in quotes (such as “Light” or ‘Light’)# String
day1 = "Light"
print(day1) # Output: Light
print(type(day1)) # Output: <class 'str'>
int
: represent integers or whole numbers (such as 1, 2, 3)