Python tutorial #5 : Basic writing, sequential progress

python

I will explain the sequential progress, which is the basic way of writing a program.

Program basics

python

The program processes statements in order from the top

python

Assuming that each code is a box, the program is completed by putting the statement in this box.

python

Assuming that each code is a box, the program is completed by putting the statement in this box. When this statement is displayed in python, it is code_A = "B"

No spaces can be used in the code on the left. If you want to put a space, use an underscore instead of the space

A string that can be used as a box name in Python

abcdefghijklmnopqrstuvwxyz
ABCDEFGHIJKLMNOPQRSTUVWXYZ
0123456789
_

Numbers cannot be used as initials

Underbar can be used

OK
_01 _ape

NG
01 1ape

python Reserved word

False  None  True  and  as  assert  async  await  break  class  continue  def
del  elif  else  except  finally  for  from  global  if  import  in  is  lambda
nonlocal  not  or  pass  raise  return  try  while  with  yield

These strings cannot be used in statements because they are reserved by python in advance.

str int float

python

Attributes are added to the code specified in python. There are mainly two attributes, the str (string) character attribute and the int (integer) integer attribute.

Difference in int float

python

int (integer) and float (floating point) are handled differently in python. Sequences with numbers with a decimal point are treated as floats. Float is mainly used for machine learning. It is safer not to use the decimal point unless you are familiar with python programs.

About str

python

All strings enclosed in ' single quotation marks or " double quotation marks are treated as str.

Both ' and " are treated the same.

The recommendation is to unify with "

The reason is

`12`
'12'
"12"

Because single quotes and back quotes are similar, it's safer to use "

"" Handling of str numbers

All strings and sequences enclosed in quotes are processed as str.

code_a = 10
code_b = 10.0
code_c = "10.0"

print(type(code_a))
print(type(code_b))
print(type(code_c))

<class 'int'>
<class 'float'>
<class 'str'>

How to start a python .py file

How to start the created ○○ .py file in the terminal

python-test/test.py

code_a = 10
code_b = 10.0
code_c = "10.0"

print(type(code_a))
print(type(code_b))
print(type(code_c))

Create a test.py file in the python-test hierarchy.

In the python test hierarchy on terminal

python

You can run the program in the test.py file by running python test.py

Please refer to python environment construction method for how to build the environment.

Also, if python2 and python3 are confused in the terminal environment

python

The code works by executing python3 〇〇.py

thank you

Thank you for watching until the end. I'm glad if you can use it as a reference.

Thank you for Helping

Give money to us for Amazon gift

We will continue to update useful information. I am delighted to jump to your help. Thank you very much.