Python basics

Basic knowledge of Python. This is my study memo. Please do not excessive expectations.

Basic knowledge

-The extension of the Python program file is py 例:××××.py

When using IDLE

・ Shell window IDLE started

・ Editor window -The one that inputs the program is called a text editor -Create new file-> " File "->" New File " in the menu bar of IDLE's shell window -Save-> When writing a program in the editor window and saving the file, " File "->" Save as ... " in the menu bar of the editor window. -Open File-> " File "->" Open " in the menu bar of the editor window -Run program-> "Run"-> "Run Module F5" in the menu bar of the editor window `

order

-Output print () Use the command print () to output a character string regardless of whether it is full-width or half-width. Also, to handle character strings, use double quotation ("") andsingle quotation ('')to wrap around. Example: print ("Good morning") → Good morning

・ Input ʻinput () If you use it likevariable = input ('the string you want to display on the console')`, the value entered in the console will be assigned to the variable. Also, since the value received by input becomes a character string type, it is necessary to convert it to a numeric type (use "int").

variable

・ How to name variables -1, Use English words, the first letter of the variable name cannot be a number Example: date -2, When using variable names of two or more words, separate words with _ (underscore) Example: user_name

-Retrieve the value of a variable

name = "Jhon"
print(name)  # → Jhon
print("name")  # → name #If you add double quotation marks, it will be recognized as a character string.

-Update the value of the variable

Uninflected word Labor-saving type
X = X + 100 X += 100
X = X - 100 X -= 100
X = X * 100 X *= 100
X = X / 100 X /= 100
X = X % 100 X %= 100

Type conversion

-Use " str " to convert a numeric type to a string type

Example


price = 200  #Numeric type
print("The price of apples"+ str(price) + "It's a yen")

-Use " int " to convert string type to numeric type

Example


count = "3"
price = 100
total_price = price * int(count)

if statement

How to write

××××.py


score = 50
if score ==100: #Colon required at end of line
    print("Equal numbers")
#Align the indents (4 half-width spaces)

××××.py


score = 50
if score ==100: #Colon required at end of line
    print("Equal numbers")
#Align the indents (4 half-width spaces)
else: #Colon required at end of line
    print("Different numbers")
#Align the indents (4 half-width spaces)

××××.py


score = 80
if score ==100: #Colon required at end of line
    print("Equal numbers")
#Align the indents (4 half-width spaces)
elif score >=70: #Colon required at end of line
    print("Greater than 70")
else: #Colon required at end of line
    print("Different numbers")
#Align the indents (4 half-width spaces)

××××.py


# and -"When both condition 1 and condition 2 are satisfied"
x = 20
if x>=10 and x<=30:
    print("x is 10 or more and 30 or less")

# or -"When condition 1 or condition 2 is satisfied"
y = 60
if y<10 or y>30:
    print("y is less than 10 or greater than 30")

# not -"If the conditional expression is False, it will be True"
z = 55
if not z== 77:
    print("z is not 77")

formula meaning
== When the right side and the left side are equal
!= When the right side and the left side are not equal
< When the time on the right side is large
<= When the time on the right side is large or equal
> When the time on the left side is large
>= When the time on the left side is large or equal

Recommended Posts

Python basics
Python basics ④
Python basics ③
Python basics
Python basics ③
Python basics ②
Python basics ②
Python basics: list
Python basics memorandum
#Python basics (#matplotlib)
Python CGI basics
Python basics: dictionary
Basics of python ①
Python slice basics
#Python basics (scope)
#Python basics (#Numpy 1/2)
#Python basics (#Numpy 2/2)
#Python basics (functions)
Python array basics
Python profiling basics
Python #Numpy basics
Python basics: functions
#Python basics (class)
Python basics summary
Python basics ② for statement
Python: Unsupervised Learning: Basics
Python
Basics of Python scraping basics
Python basics 8 numpy test
Errbot: Python chatbot basics
#Python DeepLearning Basics (Mathematics 1/4)
Python basics: Socket, Dnspython
# 4 [python] Basics of functions
Basics of python: Output
python: Basics of using scikit-learn ①
Python basics: conditions and iterations
Paiza Python Primer 4: List Basics
Basics of Python × GIS (Part 1)
kafka python
Basics of Python x GIS (Part 3)
Python Summary
Built-in python
Paiza Python Primer 5: Basics of Dictionaries
Python comprehension
Python technique
Studying python
Python 2.7 Countdown
Python FlowFishMaster
SNS Python basics made with Flask
Python service
python tips
Linux basics
python function ①
Python memo
ufo-> python (3)
Python comprehension
install python
NumPy basics
Python Memorandum 2
python memo
Python Jinja2