Created
March 1, 2018 15:01
-
-
Save enseitankad0/110cdbe0640e879baa36d14d5f50237c 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
# this is a test line in project 2 | |
string1 = 'this as the same' | |
string2 = "as below" | |
print(string1 +" " + string2) | |
# print(string1) | |
print(string1[0]) # [t] his is as the same... | |
print(len(string1)) | |
print(string1[-1]) # this is as the sam[e]... | |
# string[-2]='x' --> error, string is not mutable | |
print(string1[:5]) ## -> "this" | |
print(string1[10:]) ## -> "e same" | |
string3 = 2*'con'+'catenation' # --> conconcatenation | |
print(string3) | |
word1 = 'Melly' | |
word2 = 'K' + word1[1:] | |
print(word2) | |
### OPERATION ON STRING ### | |
print('today, Kamil had {0} cups of {1}'.format(3,'coffe')) ## today Kamil had 3 cups of coffe | |
print('prices: ({x},{y},{z})'.format(x=2.0,y=1.5,z=5)) | |
# alingment | |
print('the {vehicle} had {0} crashes in {1} month'.format(5,12,vehicle='tesla')) | |
'' | |
print('{:<20}'.format('text')) | |
print('{:>20}'.format('text')) | |
#convert to binary or hex format | |
print('{:b}'.format(21)) # 10101 | |
print('{:x}'.format(21)) #15 | |
# making quotations | |
print("I'm a quaition") #You need to use " " when ' is inside | |
#scaping characters | |
print('I\'m string in "python"') #using 2 types of " " '' | |
print(""" | |
this | |
is | |
user defined | |
output | |
""") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment