condition = True
if condition:
x = 1
else:
x = 0
print(x)
after
x = 1 if condition else 0
print(x)
num1 = 10000000000
num1 = 10_000_000_000 # clear
print(f'{num1:,}`)
f = open('test.txt','r')
file_contents = f.read()
f.close()
words = file_contents.split(' ')
word_count = len(words)
print(word_count)
after
with open('test.txt','r') as f:
file_contents = f.read()
names = ['past', 'now', 'future']
index = 0
for name in names:
print(index,name)
index += 1
after
for index, name in enumerate(names,start=1):
print(index, name)
zip
names = ['Peter Parker','Clark Kent','Bruce Wayne']
heros = ['Spiderman','Superman','Batman']
for index, name in enumerate(names):
hero = heros[index]
print(f'{name} is actually {hero}')
after
for name, hero in zip (names, heros):
print(f'{name} is actually {helo}')
names = ['Peter Parker','Clark Kent','Bruce Wayne']
heros = ['Spiderman','Superman','Batman']
universes = ['Marvel','DC','DC']
for name, hero, universe in zip (names, heros, universes):
print(f'{name} is actually {helo} from {universe}')
from getpass import getpass
username = input('Yourname: ')
password = getpass('Password: ')
repassword = getPass('Again: ')
print('Logging in...')