current position:Home>Chapter 2: Fundamentals of python-5 Boolean
Chapter 2: Fundamentals of python-5 Boolean
2022-01-30 12:38:29 【Small horn】
Python Boolean
The goal is
In this article , You will understand Python Boolean data type 、 False and true values .
Python Introduction to Boolean data types
In programming , You often want to check whether the condition is true , And perform some operations according to the results .
To show true and false ,Python Boolean data type is provided . Boolean values have a technical name bool.
Boolean data types have two values :True
and False
.
Be careful , Boolean value True and False In capital letters (T) and (F) start .
The following example defines two Boolean variables :
is_active = True
is_admin = False
Copy code
When you compare two numbers ,Python The result will be returned as a Boolean value . for example :
>>> 20 > 10
True
>>> 20 < 10
False
Copy code
Again , Comparing two strings yields a Boolean value :
>>> 'a' < 'b'
True
>>> 'a' > 'b'
False
Copy code
bool() function
To determine a value is True
still False
, have access to bool()
function . for example :
>>> bool("Hi")
True
>>> bool (' ')
False
>>> bool(100)
True
>>> bool(0)
False
Copy code
It is clear from the output that , Some values are calculated as True, Other values are calculated as False.
False and true values
When a value is calculated as True
when , It's true . If a value equals False
, It's fake .
Here are Python False values in :
- Numbers 0(
0
) - An empty string
' '
False
None
- An empty list
[]
- An empty tuple
()
- An empty dictionary
{}
True values are other true values .
Please note that , In the following article , You will learn about None、 list 、 More information about tuples and dictionaries .
summary
- Python Boolean data types have two values :True and False.
- Use bool() Function to test a value is True still False.
- The false value is calculated as False, The true value is calculated as True.
- False values are numbers 0、 An empty string 、False、None、 An empty list 、 Empty tuples and empty dictionaries . True value is not false value .
copyright notice
author[Small horn],Please bring the original link to reprint, thank you.
https://en.pythonmana.com/2022/01/202201301238262042.html
The sidebar is recommended
- Some people say Python does not support function overloading?
- "Python instance" was shocked and realized the dirty words and advertisement detection of the chat system with Python
- Introduction to Python - CONDA common commands
- Python actual combat | just "4 steps" to get started with web crawler (with benefits)
- Don't know what to eat every day? Python to tell you! Generate recipes and don't worry about what to eat every day!
- Are people who like drinking tea successful? I use Python to make a tea guide! Do you like it?
- I took 100g pictures offline overnight with Python just to prevent the website from disappearing
- Binary operation of Python OpenCV image re learning and image smoothing (convolution processing)
- Analysis of Python event mechanism
- Iterator of Python basic language
guess what you like
-
Base64 encryption and decryption in Python
-
Chapter 2: Fundamentals of python-2 variable
-
Python garbage collection summary
-
Python game development, pyGame module, python takes you to realize a magic tower game from scratch (1)
-
Python draws a spinning windmill with turtle
-
Deep understanding of Python features
-
A website full of temptations for Python crawler writers, "lovely picture network", look at the name of this website
-
Python opencv Canny edge detection knowledge supplement
-
Complex learning of Python opencv Sobel operator, ScHARR operator and Laplacian operator
-
Python: faker extension package
Random recommended
- Python code reading (Part 44): find the location of qualified elements
- Elegant implementation of Django model field encryption
- 40 Python entry applet
- Pandas comprehensive application
- Chapter 2: Fundamentals of python-3 character string
- Python pyplot draws a parallel histogram, and the x-axis value is displayed in the center of the two histograms
- [Python crawler] detailed explanation of selenium from introduction to actual combat [1]
- Curl to Python self use version
- Python visualization - 3D drawing solutions pyecharts, Matplotlib, openpyxl
- Use python, opencv's meanshift and CAMSHIFT algorithms to find and track objects in video
- Using python, opencv obtains and changes pixels, modifies image channels, and trims ROI
- [Python data collection] university ranking data collection
- [Python data collection] stock information collection
- Python game development, pyGame module, python takes you to realize a magic tower game from scratch (2)
- Python solves the problem of suspending execution after clicking the mouse in CMD window (fast editing mode is prohibited)
- [Python from introduction to mastery] (II) how to run Python? What are the good development tools (pycharm)
- Python type hints from introduction to practice
- Python notes (IX): basic operation of dictionary
- Python notes (8): basic operations of collections
- Python notes (VII): definition and use of tuples
- Python notes (6): definition and use of lists
- Python notes (V): string operation
- Python notes (IV): use of functions and modules
- Python notes (3): conditional statements and circular statements
- Python notes (II): lexical structure
- Notes on python (I): getting to know Python
- [Python data structure series] - tree and binary tree - basic knowledge - knowledge point explanation + code implementation
- [Python daily homework] Day7: how to combine two dictionaries in an expression?
- How to implement a custom list or dictionary in Python
- 15 advanced Python tips for experienced programmers
- Python string method tutorial - how to use the find() and replace() functions on Python strings
- Python computer network basics
- Python crawler series: crawling global airport information
- Python crawler series: crawling global port information
- How to calculate unique values using pandas groupby
- Application of built-in distribution of Monte Carlo simulation SciPy with Python
- Gradient lifting method and its implementation in Python
- Pandas: how to group and calculate by index
- Can you create an empty pandas data frame and fill it in?
- Python basic exercises teaching! can't? (practice makes perfect)