[Python] Minutes of study meeting for beginners (7/15)

7/15 21: 00 ~ Held at ZOOM


――By the way, what is Bool type? --while statement --break statement --Chat

By the way, what is the Bool type?

Bool types have True and False.

Use the type method to check the type of the object you normally use.

Try: Let's reconfirm what type of object we usually use.

Answer example


# => <class 'int'>
# => <class 'str'>
# => <class 'bool'>
# => <class 'bool'>

A conditional expression of an if statement that is used casually. The contents are basically Bool type. In other words, when creating a condition, make sure that the formula is a Bool type.


hoge = True
if hoge:
    print('The contents of hoge is True')
    print('The contents of hoge is False')
# =>The contents of hoge is True

By the way, operators such as ==, > and ʻor`, which are often used in conditional expressions, are also returned as Bool type.


a = 0
b = 1
print(a == b)
# => False
print(a < b)
# => True
print(a == b or a < b)
# => True

So far, the basics are basic, but just knowing that the conditional expression is a Bool type, it seems that the if statement that I have already studied and the while statement that I will study will be easier to understand, so I added it to the agenda.

As an application, since true and 1, false and 0 are equivalent


print(True == 1)
print(False == 0)

Both return True. Find out why this happens.

while statement

The while statement is the basic syntax used for iterative processing.


while conditional expression:
Iterative processing when the condition is True

For example, when "output 1 to 10"


i = 1  #It is called a loop variable. Prepare to count
while i <= 10:
    print(f'The numbers are{i}')
    i += 1  #I'm adding one by one. Without this, the condition would be True and an infinite loop.

Try: Let's output 2 to the 0th power to 2 to the 10th power. (Any number to the 0th power is 1)

Answer example


i = 0
while i <=10:
    print(2 ** i)  #  **Find the multiplier with the operator
    i += 1

break statement

The break statement is used to get out of the iterative process.


i = 0
while 1:
    if i > 2:
    i += 1
# => 0
# => 1
# => 2
# => 3

Try: Let's create a program that outputs "Please enter characters" until "exit" is entered. By the way, why does while 1: make an infinite loop? Let's go back to the Bool type story

Answer example


while 1:
    str = input('Please enter the characters>> ')
    if str == 'exit':


Recommended Posts

[Python] Minutes of study meeting for beginners (7/15)
python textbook for beginners
OpenCV for Python beginners
Easy understanding of Python for & arrays (for super beginners)
Basic story of inheritance in Python (for beginners)
Learning flow for Python beginners
[For beginners] How to study Python3 data analysis exam
Summary of pre-processing practices for Python beginners (Pandas dataframe)
Python3 environment construction (for beginners)
Overview of Docker (for beginners)
Python #function 2 for super beginners
Basic Python grammar for beginners
100 Pandas knocks for Python beginners
Python for super beginners Python #functions 1
Python #list for super beginners
~ Tips for beginners to Python ③ ~
[For beginners] Basics of Python explained by Java Gold Part 2
[For beginners] Summary of standard input in Python (with explanation)
■ Kaggle Practice for Beginners --Introduction of Python --by Google Colaboratory
[Python] The biggest weakness / disadvantage of Google Colaboratory [For beginners]
[For beginners] Basics of Python explained by Java Gold Part 1
Python Exercise for Beginners # 2 [for Statement / While Statement]
Python for super beginners Python # dictionary type 1 for super beginners
Python #index for super beginners, slices
<For beginners> python library <For machine learning>
[Must-see for beginners] Basics of Linux
Python #len function for super beginners
Beginners use Python for web scraping (1)
Run unittests in Python (for beginners)
Introductory table of contents for python3
Memorandum of beginners Python "isdigit" movement
Beginners use Python for web scraping (4) ―― 1
Python #Hello World for super beginners
Python for super beginners Python # dictionary type 2 for super beginners
Record of Python introduction for newcomers
Basic study of OpenCV with Python
Learn the basics of Python ① Beginners
[Python machine learning] Recommendation of using Spyder for beginners (as of August 2020)
Python techniques for those who want to get rid of beginners
INSERT into MySQL with Python [For beginners]
Memorandum of python beginners About inclusion notation
Summary of various for statements in Python
Let's put together Python for super beginners
Pandas of the beginner, by the beginner, for the beginner [Python]
[Python] Read images with OpenCV (for beginners)
Summary of useful techniques for Python Scrapy
Study on Tokyo Rent Using Python (3-1 of 3)
WebApi creation with Python (CRUD creation) For beginners
Atcoder standard input set for beginners (python)
[For beginners] Try web scraping with Python
A textbook for beginners made by Python beginners
For beginners of SageMaker --Collection of material links -
[Example of Python improvement] What is the recommended learning site for Python beginners?
Procedure from AWS CDK (Python) development to AWS resource construction * For beginners of development
Easy-to-understand explanation of Python Web application (Django) even for beginners (2) [Project creation]
Easy-to-understand explanation of Python Web application (Django) even for beginners (1) [Environment construction]
2016-10-30 else for Python3> for:
python [for myself]
Python study note_002
Data analysis in Python Summary of sources to look at first for beginners
The fastest way for beginners to master Python