|
| 1 | +# spam = 'Hello World!' |
| 2 | +# print(spam.islower()) |
| 3 | +# |
| 4 | +# spam='hello world!' |
| 5 | +# print(spam.islower()) |
| 6 | +# |
| 7 | +# spam = 'HELLO WORLD!' |
| 8 | +# print(spam.isupper()) |
| 9 | +# |
| 10 | +# spam = '' |
| 11 | +# print(spam.isupper()) |
| 12 | +# print(spam.islower()) |
| 13 | + |
| 14 | +# '12345'.islower() |
| 15 | + |
| 16 | +# print('Hello'.upper().isupper()) |
| 17 | + |
| 18 | +'''Other operators: |
| 19 | +isalpha() -- Letters |
| 20 | +isalnum() -- Letters and numbers |
| 21 | +isdecimal() -- Numbers |
| 22 | +isspace() -- whitespace |
| 23 | +istitle() -- titlecase |
| 24 | +''' |
| 25 | + |
| 26 | +# print('hello'.isalpha()) |
| 27 | +# print('hello123'.isalpha()) |
| 28 | +# print('hello123'.isalnum()) |
| 29 | +# print('123'.isdecimal()) |
| 30 | +# print(' '.isspace()) |
| 31 | +# print('hello world!'.isspace()) |
| 32 | +# print('hello world!'[5].isspace()) |
| 33 | +# print('This Is Title Case.'.istitle()) |
| 34 | + |
| 35 | +#Starts with and ends with... |
| 36 | +# print('Hello World!'.startswith('Hello')) |
| 37 | +# print('Hello World!'.startswith('H')) |
| 38 | +# print('Hello World!'.startswith('ello')) |
| 39 | +# print('Hello World!'.endswith('World!')) |
| 40 | + |
| 41 | + |
| 42 | + |
| 43 | +# join |
| 44 | +print(','.join(['cats', 'rats','bats'])) |
| 45 | +print(''.join(['cats', 'rats','bats'])) |
| 46 | +print('\n\n'.join(['cats', 'rats','bats'])) |
| 47 | + |
| 48 | +# .split |
| 49 | +print('My name is Simon'.split()) |
| 50 | + |
| 51 | +print('My name is Simon'.split('m')) |
| 52 | + |
| 53 | +#ljust() and rjust() and center() |
| 54 | +print('Hello'.rjust(10)) |
| 55 | +print('Hello'.ljust(20)) |
| 56 | +print('Hello'.rjust(10, '*')) |
| 57 | +print('Hello'.ljust(25, '-')) |
| 58 | +print('Hello'.center(20)) |
| 59 | +print('Hello'.center(20, '=')) |
| 60 | + |
| 61 | + |
| 62 | +#strip, rstrip, lstrip |
| 63 | +spam = 'Hello'.rjust(10) |
| 64 | +spam.strip() |
| 65 | +print(spam) |
| 66 | +spam = spam.strip() |
| 67 | +print(spam) |
| 68 | + |
| 69 | +print(' z '.strip()) |
| 70 | +print(' z '.lstrip()) |
| 71 | +print(' z '.rstrip()) |
| 72 | + |
| 73 | + |
| 74 | +print('SpamSpamBaconSpamEggsSpamSpam'.strip('ampS')) |
| 75 | + |
| 76 | + |
| 77 | + |
| 78 | +# replace |
| 79 | +spam = 'Hello there!' |
| 80 | +print(spam.replace('e', 'XYZ')) |
| 81 | + |
| 82 | + |
| 83 | +# The pyperclip module -- Copy and paste from the clipboard |
| 84 | +import pyperclip |
| 85 | +pyperclip.copy('Hello!!!!!!!!') |
| 86 | +print(pyperclip.paste()) |
| 87 | + |
| 88 | + |
| 89 | + |
| 90 | + |
| 91 | +# String Formatting |
| 92 | + |
| 93 | +print('hello ' + 'world!') |
| 94 | + |
| 95 | +name = 'Alice' |
| 96 | +place = 'Main Street' |
| 97 | +time = '6 pm' |
| 98 | +food = 'turnips' |
| 99 | + |
| 100 | +print('Hello ' + name + ', you are invited to a party at ' \ |
| 101 | + + place + ' at ' + time + '. Please bring ' + food + '.') |
| 102 | + |
| 103 | +print('Hello %s, you are invited to a party at %s at\ |
| 104 | + %s. Please bring %s.' % (name, place, time, food)) |
| 105 | + |
| 106 | + |
| 107 | +print('-'.join('There can be only one.'.split())) |
0 commit comments