Python beginners talk about how to remember this much

Introduction

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!

8 basics

# 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.

at the end

It's super basic, but I hope it helps someone. Surprisingly, I was surprised that I could call it without a script.

Recommended Posts

Python beginners talk about how to remember this much
How to make Python faster for beginners [numpy]
How to install Python
How to install python
[For beginners] How to use say command in python!
How to convert Python # type for Python super beginners: str
Python # How to check type and type for super beginners
[2020.8 latest] How to install Python
How to install Python [Windows]
python3: How to use bottle (2)
[Python] How to use list 1
How to update Python Tkinter to 8.6
About python beginner's memorandum function
How to use Python argparse
3 Reasons Beginners to Start Python
Python: How to use pydub
[Python] How to use checkio
How to run Notepad ++ Python
How to change Python version
How to develop in Python
~ Tips for beginners to Python ③ ~
[python] How to judge scalar
[Python] How to use input ()
How to use Python lambda
[Python] How to use virtualenv
python3: How to use bottle (3)
python3: How to use bottle
How to use Python bytes
How to learn TensorFlow for liberal arts and Python beginners
How to convert Python # type for Python super beginners: int, float
How to install python using anaconda
How to write a Python class
[Python] How to FFT mp3 data
Python: How to use async with
[Python] How to use Pandas Series
How to collect images in Python
How to use Requests (Python Library)
How to use SQLite in Python
How to get the Python version
How to use the asterisk (*) in Python. Maybe this is all? ..
How to get started with Python
[Python] How to import the library
[For beginners] How to register a library created in Python in PyPI
[Python] How to use list 3 Added
How to use Mysql in python
How to use OpenPose's Python API
[Python] How to swap array values
How to wrap C in Python
How to use ChemSpider in Python
How to use FTP with Python
Python: How to use pydub (playback)
How to use PubChem in Python
How to speed up Python calculations
How to calculate date with python
Useful to remember! 10 Python Standard Libraries
How to access wikipedia from python
How to use python zip function
[Nanonets] How to post Memo [Python]
python beginners tried to find out
How to handle Japanese in Python
[Python] How to use Typetalk API