Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd28f87e

Browse files
committed
Add demo for string methods.
1 parent81681c3 commitd28f87e

File tree

3 files changed

+106
-0
lines changed

3 files changed

+106
-0
lines changed

‎StringMethods/.project

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>StringMethods</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.python.pydev.PyDevBuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
</buildSpec>
14+
<natures>
15+
<nature>org.python.pydev.pythonNature</nature>
16+
</natures>
17+
</projectDescription>

‎StringMethods/.pydevproject

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2+
<?eclipse-pydev version="1.0"?><pydev_project>
3+
<pydev_pathpropertyname="org.python.pydev.PROJECT_SOURCE_PATH">
4+
<path>/${PROJECT_DIR_NAME}/src</path>
5+
</pydev_pathproperty>
6+
<pydev_propertyname="org.python.pydev.PYTHON_PROJECT_VERSION">python 3.6</pydev_property>
7+
<pydev_propertyname="org.python.pydev.PYTHON_PROJECT_INTERPRETER">Default</pydev_property>
8+
</pydev_project>

‎StringMethods/src/stringmethods.py

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
'''
2+
Created on Aug 7, 2017
3+
4+
@author: Aditya
5+
This program explains the String methods in python
6+
'''
7+
8+
defmain():
9+
print('In python Everything is an object.')
10+
print('Even the strings in python are objects.')
11+
12+
print()
13+
s='This is a string!'
14+
print(s.upper())
15+
print('This is a string!'.upper())
16+
17+
s='this is a lower case string'
18+
print('Lower Case string:',s)
19+
print('Capitalized String:',s.capitalize())
20+
print('Upper Case: ',s.upper())
21+
print('Lower case:',s.lower())
22+
23+
s='This Is A Sample'
24+
print(s)
25+
print(s.swapcase())
26+
print('Print location of\'sam\' in string:',s.find('Sam'))
27+
28+
print(s.replace('Sample','String'))
29+
30+
s=' There is a space at the begining and at the end. '
31+
print(s)
32+
print(s.strip())
33+
print(s.rstrip())
34+
35+
s=' String with new line at end\n'
36+
print(s)
37+
print(s.strip())
38+
print(s.rstrip('\n'))
39+
40+
s='This is a string'
41+
42+
print('Check if string\'{}\'has only alpha numeric characters in it'.format(s),'This is false as string has\'spaces\' in it.')
43+
print(s.isalnum())
44+
45+
s='thisisastring'
46+
print(s)
47+
print('Only_alphanumeric:',s.isalnum())
48+
print('check only for letters in string:',s.isalpha())
49+
print('check if string has only digits:',s.isdigit())
50+
51+
s='06.3'
52+
print(s)
53+
print('check for digits string:',s.isdigit())
54+
print('check decimal:',s.isdecimal())
55+
56+
s='1223456'
57+
print('check for digits:',s.isdigit())
58+
print('check if printable:',s.isprintable())
59+
60+
a,b=5,6
61+
print('A = {}, B = 6'.format(a,b))
62+
print('B = {1}, A = {0}, B = {1}'.format(a,b))
63+
print('A({Addo}) and B({Mado})'.format(Addo=333,Mado=4443))
64+
65+
66+
print()
67+
print('Splitting and Joining Strings:')
68+
s='This is a string.'
69+
a=s.split()
70+
print(a)
71+
print('Splitting at\'i\' in string: ',s.split('i'))
72+
73+
forwina:print(w)
74+
75+
s1=':'.join(a)
76+
s2=', '.join(a)
77+
s3=' '.join(a)
78+
s4=''.join(a)
79+
print('{}\n{}\n{}\n{}'.format(s1,s2,s3,s4))
80+
81+
if__name__=='__main__':main()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp