Converting from a string to boolean in Python

Опубликовано: 20 Ноябрь 2016
на канале: The American Developer
1,650
5

PLEASE COMMENT, SUBSCRIBE, AND SHARE!!!
I know I have personally run into this problem many times when I first started learning python, mainly due to forgetting what builtin functions did what. Thankfully, stackoverflow

This is what I wrote for this video:

Todo:
1. Create a string variable that is True or False
and convert it to a boolean data type

stringvariable = 'True'
print bool(stringvariable)# 1.1 This will print
out the boolean version of stringvariable

2. Now we will test to see if the variable has truly
changed from a string to a boolean:
if (bool(stringvariable) is True):
print 'Please comment and subscribe!'

Inspired by this stackoverflow link: http://stackoverflow.com/questions/71...