Skip to content

Instantly share code, notes, and snippets.

@Robofied
Created February 4, 2019 19:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Robofied/07b1812f676f07e52898af04477e2927 to your computer and use it in GitHub Desktop.
Save Robofied/07b1812f676f07e52898af04477e2927 to your computer and use it in GitHub Desktop.
## Simply using print
name = input('what is your name?t')
print(name)
#[Output]:
#what is your name? branson
#branson
## If we want to repeat a string string or number multiple times then we can do like this.
print('number! '*3)
print('3! '*3)
#[Output]:
#number! number! number!
#3! 3! 3!
## How to use str.format()
name = 'Richard Branson'
'Your name is {}'.format(name)
#[Output]:
#'Your name is Richard Branson'
Country = 'USA'
'My name is {} and lives in {}'.format(name,Country)
#[Output]:
#'My name is Richard Branson and lives in USA'
## We want to change the order then can access it as follows {number}
'My country is {1} and name is {0}'.format(name,Country)
#[Output]:
#'My country is USA and name is Richard Branson'
## More Formatting
import math
## It will print a whole long number.
print('%f' %math.pi)
## If we want to print upto 3 decimals we can do this
#[Output]:
#3.141593
#3.142
print('%.3f' %math.pi)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment