Skip to content

Commit 269f370

Browse files
author
vijay patel
committed
cosmetic change and added support in string
1 parent d514b05 commit 269f370

10 files changed

+352
-0
lines changed
+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Python String Formating Demostration
2+
3+
# Python program to demonstrate the
4+
# use of capitalize() function
5+
6+
# capitalize() first letter of
7+
# string.
8+
example = "Python LEARNINF"
9+
print ("String make to capitalize\n")
10+
print(example.capitalize())
11+
12+
# demonstration of individual words
13+
# capitalization to generate camel case
14+
name1 = "hello"
15+
name2 = "world"
16+
print ("2 String make to capitalize\n")
17+
print(name1.capitalize() + name2.capitalize())
18+
19+
# Python code for implementation of isupper()
20+
21+
# checking for uppercase characters
22+
string = 'PYTHON LEARNING'
23+
print (string)
24+
print ("\nChecking String is upper case\n")
25+
print(string.isupper())
26+
print ("\nChanging string upper case to lower\n")
27+
#change staring case using lower function
28+
print (string.lower())
29+
30+
string = 'python learning'
31+
# Python code for implementation of isupper()
32+
# checking for uppercase characters
33+
print (string)
34+
print ("\nChecking String is upper case\n")
35+
print(string.isupper())
36+
#change staring case using lower function
37+
print ("\nChanging string lower case to upper\n")
38+
print (string.upper())
39+
40+
string = "Python Learning"
41+
# Python code for implementation of swapcase()
42+
print (string)
43+
print ("\nChanging string case using swapcase function\n")
44+
print (string.swapcase())
45+
46+
string = "python learning"
47+
# Python code for implementation of title()
48+
print (string)
49+
print ("\n make title of string\n")
50+
print (string.title())
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#Python String Replacing Demostration
2+
3+
# Python3 program to demonstrate the
4+
# use of replace() method
5+
6+
example = "Hello World"
7+
# Prints the string by replacing geeks by Geeks
8+
print(example.replace("World", "India"))
9+
10+
example = "Hello World World World"
11+
# Prints the string by replacing only 3 occurence of Geeks
12+
print(example.replace("World", "India", 2))
13+
14+
#concatenation with spliting and string
15+
example = "Spammy"
16+
example= example [:2]+'ic'+example[5:]
17+
print(example)
18+
19+
example = "Hello"
20+
example= example.replace('e','P')
21+
print(example)
22+
23+
#How to get the supported function of string
24+
print(dir(example))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Python String Variable Demostration
2+
3+
# Declaration
4+
x="python"
5+
6+
#condition in string with small latter
7+
print ('t' in x)
8+
9+
10+
#condition in string with capital latter
11+
print ('T' in x)
12+
13+
#String print
14+
print (x)
15+
16+
# String lenght printed
17+
print (len(x))
18+
19+
#How to add new line in print
20+
x= "Python\nTest"
21+
print(x)
22+
23+
#How to add new line in print
24+
x= 'Python\nTest'
25+
print(x)
26+
27+
#How to avoide special character
28+
x = r'Python\nTest'
29+
print (x)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Python String Variable Demostration
2+
3+
# Declaration
4+
5+
#String Declaration with single quote for single line display
6+
x= ''
7+
print (x)
8+
9+
#String Declaration with double quote for single line display
10+
x= " "
11+
print (x)
12+
13+
#String Declaration with multi line print with single quote
14+
x = '''Hello
15+
This is Python Multiline
16+
demo
17+
'''
18+
print (x)
19+
20+
21+
#String Declaration with multi line print with double quote
22+
x = """Hello
23+
This is Python Multiline
24+
demo
25+
"""
26+
print (x)
27+
28+
#How print works
29+
x= 'hello'
30+
#variable will br printed
31+
print (x)
32+
33+
#x as a string will be printted
34+
print ('x')
35+
36+
#x as a string will be printted
37+
print ("x")
38+
39+
#variable x will be printed in string conversation
40+
print (str(x))
41+
42+
#repr() representation that has all information
43+
print (repr(x))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#Python String Demostration
2+
3+
#How to club with other character
4+
example = "test"
5+
print ('w' + example[1:])
6+
7+
#Converting String to list
8+
list_example=list(example)
9+
print ("String Data Type value is :",example)
10+
print ("List data type:",list_example)
11+
12+
#Converting String to set
13+
set_example=set(example)
14+
print ("String Data Type value is :",example)
15+
print ("Set data type:",set_example)
16+
17+
#Converting String to boolean
18+
boolean_example=bool(example)
19+
print ("String Data Type value is:",example)
20+
print ("Boolean data type:",boolean_example)
21+
22+
example =''
23+
#Converting String to boolean with blank value
24+
boolean_example=bool(example)
25+
print ("String Data Type value is:",example)
26+
print ("Boolean data type:",boolean_example)
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#Python String immutable Demostration
2+
3+
#Sting is immutable we can not change the value from indexing
4+
example="python"
5+
6+
print ("first character of string\n",example[0])
7+
8+
example[0] = "S"
9+
10+
print ("first character of string\n",example[0])
11+
12+
#TypeError: 'str' object does not support item assignment
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#Demostration of Pythong String Indexing
2+
3+
example= "Python Scripting"
4+
5+
"""
6+
P Y T H O N S C R I P T I N G
7+
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 (Sequecebe )
8+
-16-15 -14 -13 -12 -11 -10 -9 -8 -7 -6 -5 -4 -3 -2 -1 ()
9+
"""
10+
11+
print("Initial String: ")
12+
print(example)
13+
14+
# Printing First character
15+
print("\nFirst character of String is: ")
16+
print(example[0])
17+
#output would be P
18+
19+
print ("\n7th Character of String is:\n",example[7])
20+
#this will print only S
21+
22+
# Printing Last character
23+
print("\nLast character of String is: ")
24+
print(example[-1])
25+
#output would be G
26+
27+
# Printing 3rd to 12th character
28+
print("\nSlicing characters from 3-12: ")
29+
print(example[3:12])
30+
#output would be "hon Script"
31+
32+
# Printing characters between
33+
# 3rd and 2nd last character
34+
print("\nSlicing characters between " + "3rd and 2nd last character: ")
35+
print(example[3:-2])
36+
#hon Script
37+
38+
#printing character from 1 to end
39+
print ("\nCharacter from 1 to :")
40+
print (example[1:])
41+
42+
#printing character from 1 to 6
43+
print ("\nCharacter from 1 to 6")
44+
print (example[1:6])
45+
46+
#printing character from 1 to 12
47+
print ("\nCharacter from 1 to 12")
48+
print (example[1:12])
49+
50+
#printing character from 1 to 12 with increment by 2
51+
print ("\nCharacter from 1 to 12 with increment by 2")
52+
print (example[1:12:2])
53+
54+
55+
#printing character from 1 to 12 with increment by 2
56+
print ("\nCharacter from -3 to -1 with increment by 2")
57+
print (example[-9:-1:-1])
58+
59+
#printing character from -3 -15 in reverse order
60+
print ("\nCharacter from -3 -15 in reverse order")
61+
print (example[-3::-1])
+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
##############################################
2+
####### Python exampleing Start with and End with
3+
###############################################
4+
# Python exampleing method startswith()
5+
# checks whether exampleing starts with example,
6+
# optionally reexampleicting the matching
7+
# with the given indices start and end.
8+
9+
10+
# Syntex example.startswith(example, beg=0,end=len(exampleing));
11+
12+
example = "python";
13+
print ("example start with p")
14+
print example.startswith( 'p' )
15+
# output is
16+
# example start with p
17+
# True
18+
19+
print ("example start with P")
20+
print example.startswith( 'P' )
21+
# output is
22+
# example start with P
23+
# False
24+
25+
print ("example start with Y")
26+
print example.startswith( 'y' )
27+
# output is
28+
# example start with Y
29+
# False
30+
31+
print ("example start with y at index 1")
32+
print example.startswith( 'y', 1 )
33+
# output is
34+
# example start with y at index 1
35+
# True
36+
37+
print ("example start with y at index 1 till 4 length of string")
38+
print example.startswith( 'y', 1, 4 )
39+
# output is
40+
# example start with y at index 1 till 4 length of string
41+
# True
+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#Python String concatation Example
2+
3+
a = "Python"
4+
b = "scripting"
5+
6+
print (a+b)
7+
#output
8+
#Pythonscripting
9+
10+
# Adding space in two word
11+
print (a+" "+b)
12+
#Python scripting
13+
14+
#Adding new line between words
15+
print (a+'\n'+b)
16+
#Python
17+
#scripting
18+
19+
#concatation using Join
20+
print (' '.join([a, b]))
21+
#Python scripting
22+
23+
24+
#two String join
25+
print (' '.join(["Hello", "World"]))
26+
#Hello World
27+
28+
#Join using different character
29+
print (','.join(['apple','banana','strawberry']))
30+
#apple,banana,strawberry
31+
32+
x="hello"
33+
y="world"
34+
result = x+y
35+
print (result)
36+
#helloworld
37+
38+
result = 'Hello' +' ' +'World'
39+
print (result)
40+
#hello world
+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#Python String Repetation and swaping Example
2+
3+
a = "Python"
4+
5+
print ( a * 5)
6+
7+
x= "Python"
8+
y= "Shell"
9+
10+
print (x,y)
11+
#python shell
12+
13+
14+
#swaping value x to y and y to x
15+
x,y=y,x
16+
print (x,y)
17+
#Shell Python
18+
19+
# using triple quotes
20+
print('''Hello, "What's there?"''')
21+
22+
# escaping single quotes
23+
print('Hello, "What\'s there?"')
24+
25+
# escaping double quotes
26+
print("Hello, \"What's there?\"")

0 commit comments

Comments
 (0)