= 'mango'
fruit = 'voila'
name
# printing out
print(name, ' likes ', fruit )
voila likes mango
Juma Shafara
November 1, 2023
August 14, 2024
python, python programming, python variables
(=)
.
In the examples below, we create varibales name fruit
and name
and we assign them values 'mango'
and 'viola'
respectively
Before choosing a variable name, consider the following.
my age = 34
1name = 'Chris'
n@me = 'Comfort'
Examples of good variable names
Before we continue, we have a humble request, to be among the first to hear about future updates of the course materials, simply enter your email below, follow us on (formally Twitter), or subscribe to our YouTube channel.
In this section of the tutorial, you will learn the most basic data types in Python
Strings are simply text. A string must be surrounded by single or double quotes
Boolean data type can only have on fo these values: True
or False
The first letter of a Boolean is in upper case.
Booleans are often the result of evaluated expressions.
Forexample, when you compare two numbers, Python evaluates the expression and returns either True
or False
These are often used in if
statments.
In this example, if the value of the variable age
is more than 18
, the program will tell the user that they are allowed to enter
You will learn more about if statements later in the course
We can check the data type of a Boolean variable using the type()
method.
[]
)
,
)
A list can contain mixed data types
To check the data type of an object in python, use type(object)
, for example, below we get the data type of the object stored in names
The str()
method returns the string version of a given object
The int()
method returns the integer version of the given object.
The float()
method returns the floating point version of the given object.
Write a program to assign the number 34.5678 to a variable named “number” then display the number rounded to the nearest integer value.