Created
February 4, 2019 19:38
-
-
Save Robofied/07b1812f676f07e52898af04477e2927 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## 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