Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python print boolean

my_bool = True
str(my_bool) # Returns my_bool but as a string. (The word "True")

#-----How to print a bool------#
# Multi-line approach:
my_str = str(my_bool)
print(my_str) 

# One-line approach:
print(str(my_bool))
Comment

print boolean in python

print(10 > 9) #Output: True
print(10 == 9) #Output: False
print(10 < 9) #Output: False
Comment

python print bool as string

isFoo = True // our bool variable

// now we use str() to cast bool to string
print('Value of isFoo is: ' + str(isFoo)) // Value of isFoo is: True

// common mistake just for example. Don't do that
print('Value of Foo is: ' + isFoo) // TypeError: can only concatenate str (not "bool") to str
Comment

PREVIOUS NEXT
Code Example
Python :: python check if two lists intersect 
Python :: python version 
Python :: replace value in dataframe 
Python :: python list comprehension elif 
Python :: opencv waitkey example 
Python :: are tuples mutable 
Python :: pandas merge certain columns 
Python :: connecting python with database 
Python :: opencv dilate 
Python :: python print raw string 
Python :: list sort by key python 
Python :: divide a column value in pandas dataframe 
Python :: godot setget 
Python :: python resize image in tkinter 
Python :: import error in same directory python 
Python :: create and populate dictionary python 
Python :: pandas Unnamed: 0 
Python :: python groupby sum single columns 
Python :: np vstack 
Python :: qlistwidget item clicked event pyqt 
Python :: how to find the datatype of a dataframe in python 
Python :: pip install for python 2 and python3 
Python :: pandas change to first day 
Python :: fillna with mode pandas 
Python :: python convert string to sentence case 
Python :: assign multiple variables in python 
Python :: loop through a column in pandas 
Python :: how to open application using python 
Python :: smtplib send pdf 
Python :: pandas strip whitespace 
ADD CONTENT
Topic
Content
Source link
Name
1+3 =