Let's put together Python by a Python amateur (https://qiita.com/kkhouse/items/675b846d0bcf41cd191f) Continued.
This time, I will write about operations and variables in a mess. Emphasis on comprehensibility!
# 3 + 5
print(3 + 5)
# 3 - 5
print(3 - 5)
# 3 × 5
print(3 * 5)
# 3 ÷ 5
print(3 / 5)
#The remainder of dividing 3 by 5
print(3 % 5)
#3 to the 5th power
print(3 ** 5)
#Divide 3 by 2 and truncate after the decimal point
print(3 // 5)
(In Python, print () calls the numbers and strings in ().) Only power and too much notation are special. remember.
Also, keep in mind the difference between strings and numbers that I wrote last time.
#Cat dog
print("Cat"+"dog")
#8 cats
print("Cat"+ "8" + "Animal")
I feel like. By the way, if you do not enclose 8 in "" and make it a character string, an error will occur. Python can only operate between numbers and strings.
By the way, even str (8) will be a character string.
#8 cats
print("Cat"+ str(8) + "Animal")
So far, you can't see the difference between enclosing in "" and using str (), but this is useful when using variables.
For example
#Assign 8 to the variable num
num = 8
print(num)
Think of a variable as a box. It is a box to put the numbers and letters after the "=". This formula outputs 8.
If you express the eight cats earlier using variables
#8 cats
print("Cat"+str(num)+"Animal")
I'm going out. If you enclose this num in "", num will be recognized as a character string.
#Num cats
print("Cat"+ "num"+"Animal")
I feel like. num is a variable, but "" is a sign of a character string, so it's written like this.
It's super basic, but I hope it helps someone. Surprisingly, I was surprised that I could call it without a script.
Recommended Posts