Study from Python Hour2: Control statements

Study from Python Hour2: Control statements

Learning materials

environment

Create and execute a program file (.py)

Create and execute with a text file

Hello Python-san

C:\




* Try to raise an error using an undeclared variable (test_03.py)

```python
print(1)
print('2')
a = 1 + 2
print(b)

Comment line / comment range

Conditional branch

if conditional expression: Processing when the conditional expression is satisfied elif conditional expression: Processing when the second conditional expression is satisfied else: Other processing


* Example sentence

```python
a=17

if a % 2 == 0:
	print('2')
elif a % 3 == 0:
	print('3')
elif a % 5 == 0:
	print('5')
else:
	print('nothing')

list

taro ← Always the first ['hogeo', 'jiro', 'kotaro', 10]← Replace and display 4 ← Get list length Traceback (most recent call last): File "C:\test05_list.py", line 11, in print(a[4]) IndexError:list index out of range ← An error occurs because a value outside the list was acquired.




## Loop processing

* For loop. It's faster to see the sample

```python
name_list = ['taro', 'jiro', 'kotaro', 'hogeo']

for name in name_list:
	print(name)

break & continue

  nubber_list = [1, 3, 11, 15, 7, 9]
  has_even = False
  
  for i in number_list:
  	print(i)
  	if i % 2 == 0
  		has_even ~ True 
  		break
  print ('has_even=' has_even)

while statement:

  number_list = [1, 3, 11, 15, 7, 9]
  length =len(number_list)
  i = 0
  
  while i < length:
  	print('List No.' + str(i) + '=' + str(number_list[i]))
  	i += 1
  

This summary

For Quotations / Lightning Talk

Recommended Posts

Study from Python Hour2: Control statements
Study from Python Hour4: Object-oriented ②
Study from Python Hour3: Functions
Study from Python Hour4: Object-oriented ①
Study from Python Hour7: How to use classes
Study from Python Reading and writing Hour9 files
Study from the beginning of Python Hour1: Hello World
Study from the beginning of Python Hour8: Using packages
Pharmaceutical company researchers summarized Python control statements
Python study note_002
Python study notes _000
Study from Python Hour6: Frequently used data types: tuple type, set type, dictionary type
Python study notes_006
Python study note_004
sql from python
MeCab from Python
Python study note_003
Python study notes _005
Install Python Control
Python study notes_001
Python study day 1
Use thingsspeak from python
Touch MySQL from Python 3
Operate Filemaker from Python
Use fluentd from python
Access bitcoind from python
Changes from Python 3.0 to Python 3.5
Changes from Python 2 to Python 3.0
Python from or import
Use MySQL from Python
Control other programs from Python (communication between Python and exe)
Run python from excel
Install python from source
Execute command from Python
Operate neutron from Python!
Home Control from Cortana.
Use MySQL from Python
Python control syntax (memories)
Operate LXC from Python
Manipulate riak from python
Force Python from Fortran
Use BigQuery from python.
Execute command from python
[Python] Read From Stdin
Use mecab-ipadic-neologd from python
Control smart light "Yeelight" from Python without using the cloud
Flatten using Python yield from
Call CPLEX from Python (DO cplex)
Deep Python learned from DEAP
Post from Python to Slack
Grammar features added from Python3.6
[Python tutorial] Control structure tool
Make MeCab available from Python3
Information obtained from tweet_id (Python)
OCR from PDF in Python
Study Python with Google Colaboratory
Run illustrator script from python
Anaconda updated from 4.2.0 to 4.3.0 (python3.5 updated to python3.6)
Query Athena from Lambda Python
Access Oracle DB from Python
Start / stop GCE from python