To concatenate left side (our custom report) with right side, which is variable that hold string, we will use plus (+
) symbol:
name = "John"
lastname = "Snow"
years = "39"
print("Name: " + name)
print("LastName: " + lastname)
print("Years: " + years)
We can also use a comma:
name = "John"
lastname = "Snow"
years = 39
print("Name: ", name)
print("LastName: ", lastname)
print("Years: ", years)
To see with what we are dealing with (data type detection), there's type()
function:
name = "John"
lastname = "Snow"
years = 39
"""
print("Name: ", name)
print("LastName: ", lastname)
print("Years: ", years)
"""
print(type(name))
print(type(lastname))
print(type(years))
Result:
<class 'str'>
<class 'str'>
<class 'int'>
>>>
We are working with two strings (name, lastname) and one number (integer).
Sometimes, we will put result of type() function in dedicated variable, so it can be used in further operations.
We will use that approach all the time:
name = "John"
lastname = "Snow"
years = 39
"""
print("Name: ", name)
print("LastName: ", lastname)
print("Years: ", years)
"""
result = type(name)
print(result)
This will be result in Shell:
<class 'str'>
>>>
It's so easy to work with numbers in Python. Let's learn about that in next tutorial.
No comments:
Post a Comment