basic_syntax

#format #print

format

python format deatils
f-stirng


  1. new style
stat='well'
ret=0
print("the stat is {}, ret code is {}".format(stat,ret))
print("the stat is {0}, ret code is {1}".format(stat,ret))
print("the stat is {stat}, ret code is {ret}".format(stat=stat,ret=ret))

  1. old style
stat='well'
ret=0
print("the stat is %s, ret code is %d" %(stat,ret))

string

name='George'
print(f"my name is {name}")

join string

# Joining with empty separator
list1 = ['g', 'e', 'e', 'k', 's']
print("".join(list1))

# Joining with string

print("-".join(list1))

# Joining with string
list1 = " geeks "
print("$".join(list1))