Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #========================================================================================================
- #-------------str.format------------------------------------------------------
- animal = "dog"
- item = "moon"
- text = "The {} jumped over the {}"
- print(text.format(animal,item))
- #------------------------------
- print("The "+animal+" Jumped over the "+item)
- print("The {} jumped over the {}".format(animal,item))
- print("The {1} jumped over the {0}".format(animal,item)) #POSITIONAL ARGUMENT
- #-------------------------------------------------
- #========================================================================================================
- print("The {animal} jumped over the {item}".format(animal="cow",item="moon")) #KEYWORD ARGUMENT
- #---------------------------------------------------
- name = "Coded."
- print("Hello, my name is {}".format(name))
- print("Hello, my name is {0:10} Nice to meet you".format(name))
- print("Hello, my name is {:^10} Nice to meet you".format(name))
- print("Hello, my name is {:<10} Nice to meet you".format(name))
- print("Hello, my name is {:>10} Nice to meet you".format(name))
- #----------------------------------------------------
- number = 1000
- print("The number is {:.3f}".format(number))
- print("The number is {:,}".format(number)) #AUTOMATICALLY ADDS A COMMA TO ALL 1000s PLACES
- print("The number is {:b}".format(number)) #DISPLAY NUMBER AS BINARY
- print("The number is {:o}".format(number)) #DISPLAYS NUMBER AS OCTAL
- print("The number is {:x}".format(number)) #DISPLAYS NUMBER AS HEXADECIMAL
- print("The number is {:e}".format(number)) #DISPLAYS NUMBER AS SCIENTIFIC NOTATION
- #----------------------------------------------------------------------------------------------------------------
- #=================================================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement