Skip to content

String formating #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions Python-String-Basics/String-Formating.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Python String Formating Demostration

# Python program to demonstrate the
# use of capitalize() function

# capitalize() first letter of
# string.
example = "Python LEARNINF"
print ("String make to capitalize\n")
print(example.capitalize())

# demonstration of individual words
# capitalization to generate camel case
name1 = "hello"
name2 = "world"
print ("2 String make to capitalize\n")
print(name1.capitalize() + name2.capitalize())

# Python code for implementation of isupper()

# checking for uppercase characters
string = 'PYTHON LEARNING'
print (string)
print ("\nChecking String is upper case\n")
print(string.isupper())
print ("\nChanging string upper case to lower\n")
#change staring case using lower function
print (string.lower())

string = 'python learning'
# Python code for implementation of isupper()
# checking for uppercase characters
print (string)
print ("\nChecking String is upper case\n")
print(string.isupper())
#change staring case using lower function
print ("\nChanging string lower case to upper\n")
print (string.upper())

string = "Python Learning"
# Python code for implementation of swapcase()
print (string)
print ("\nChanging string case using swapcase function\n")
print (string.swapcase())

string = "python learning"
# Python code for implementation of title()
print (string)
print ("\n make title of string\n")
print (string.title())
24 changes: 24 additions & 0 deletions Python-String-Basics/String-Replacing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#Python String Replacing Demostration

# Python3 program to demonstrate the
# use of replace() method

example = "Hello World"
# Prints the string by replacing geeks by Geeks
print(example.replace("World", "India"))

example = "Hello World World World"
# Prints the string by replacing only 3 occurence of Geeks
print(example.replace("World", "India", 2))

#concatenation with spliting and string
example = "Spammy"
example= example [:2]+'ic'+example[5:]
print(example)

example = "Hello"
example= example.replace('e','P')
print(example)

#How to get the supported function of string
print(dir(example))
29 changes: 29 additions & 0 deletions Python-String-Basics/String-basic-condition.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Python String Variable Demostration

# Declaration
x="python"

#condition in string with small latter
print ('t' in x)


#condition in string with capital latter
print ('T' in x)

#String print
print (x)

# String lenght printed
print (len(x))

#How to add new line in print
x= "Python\nTest"
print(x)

#How to add new line in print
x= 'Python\nTest'
print(x)

#How to avoide special character
x = r'Python\nTest'
print (x)
43 changes: 43 additions & 0 deletions Python-String-Basics/String-basic-declaration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Python String Variable Demostration

# Declaration

#String Declaration with single quote for single line display
x= ''
print (x)

#String Declaration with double quote for single line display
x= " "
print (x)

#String Declaration with multi line print with single quote
x = '''Hello
This is Python Multiline
demo
'''
print (x)


#String Declaration with multi line print with double quote
x = """Hello
This is Python Multiline
demo
"""
print (x)

#How print works
x= 'hello'
#variable will br printed
print (x)

#x as a string will be printted
print ('x')

#x as a string will be printted
print ("x")

#variable x will be printed in string conversation
print (str(x))

#repr() representation that has all information
print (repr(x))
26 changes: 26 additions & 0 deletions Python-String-Basics/String-convert-in-other-data-type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#Python String Demostration

#How to club with other character
example = "test"
print ('w' + example[1:])

#Converting String to list
list_example=list(example)
print ("String Data Type value is :",example)
print ("List data type:",list_example)

#Converting String to set
set_example=set(example)
print ("String Data Type value is :",example)
print ("Set data type:",set_example)

#Converting String to boolean
boolean_example=bool(example)
print ("String Data Type value is:",example)
print ("Boolean data type:",boolean_example)

example =''
#Converting String to boolean with blank value
boolean_example=bool(example)
print ("String Data Type value is:",example)
print ("Boolean data type:",boolean_example)
12 changes: 12 additions & 0 deletions Python-String-Basics/String-immutable.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#Python String immutable Demostration

#Sting is immutable we can not change the value from indexing
example="python"

print ("first character of string\n",example[0])

example[0] = "S"

print ("first character of string\n",example[0])

#TypeError: 'str' object does not support item assignment
61 changes: 61 additions & 0 deletions Python-String-Basics/String-indexing-Slicing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#Demostration of Pythong String Indexing

example= "Python Scripting"

"""
P Y T H O N S C R I P T I N G
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 (Sequecebe )
-16-15 -14 -13 -12 -11 -10 -9 -8 -7 -6 -5 -4 -3 -2 -1 ()
"""

print("Initial String: ")
print(example)

# Printing First character
print("\nFirst character of String is: ")
print(example[0])
#output would be P

print ("\n7th Character of String is:\n",example[7])
#this will print only S

# Printing Last character
print("\nLast character of String is: ")
print(example[-1])
#output would be G

# Printing 3rd to 12th character
print("\nSlicing characters from 3-12: ")
print(example[3:12])
#output would be "hon Script"

# Printing characters between
# 3rd and 2nd last character
print("\nSlicing characters between " + "3rd and 2nd last character: ")
print(example[3:-2])
#hon Script

#printing character from 1 to end
print ("\nCharacter from 1 to :")
print (example[1:])

#printing character from 1 to 6
print ("\nCharacter from 1 to 6")
print (example[1:6])

#printing character from 1 to 12
print ("\nCharacter from 1 to 12")
print (example[1:12])

#printing character from 1 to 12 with increment by 2
print ("\nCharacter from 1 to 12 with increment by 2")
print (example[1:12:2])


#printing character from 1 to 12 with increment by 2
print ("\nCharacter from -3 to -1 with increment by 2")
print (example[-9:-1:-1])

#printing character from -3 -15 in reverse order
print ("\nCharacter from -3 -15 in reverse order")
print (example[-3::-1])
41 changes: 41 additions & 0 deletions Python-String-Basics/String-start-with.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
##############################################
####### Python exampleing Start with and End with
###############################################
# Python exampleing method startswith()
# checks whether exampleing starts with example,
# optionally reexampleicting the matching
# with the given indices start and end.


# Syntex example.startswith(example, beg=0,end=len(exampleing));

example = "python";
print ("example start with p")
print example.startswith( 'p' )
# output is
# example start with p
# True

print ("example start with P")
print example.startswith( 'P' )
# output is
# example start with P
# False

print ("example start with Y")
print example.startswith( 'y' )
# output is
# example start with Y
# False

print ("example start with y at index 1")
print example.startswith( 'y', 1 )
# output is
# example start with y at index 1
# True

print ("example start with y at index 1 till 4 length of string")
print example.startswith( 'y', 1, 4 )
# output is
# example start with y at index 1 till 4 length of string
# True
40 changes: 40 additions & 0 deletions Python-String-Basics/string-concatation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#Python String concatation Example

a = "Python"
b = "scripting"

print (a+b)
#output
#Pythonscripting

# Adding space in two word
print (a+" "+b)
#Python scripting

#Adding new line between words
print (a+'\n'+b)
#Python
#scripting

#concatation using Join
print (' '.join([a, b]))
#Python scripting


#two String join
print (' '.join(["Hello", "World"]))
#Hello World

#Join using different character
print (','.join(['apple','banana','strawberry']))
#apple,banana,strawberry

x="hello"
y="world"
result = x+y
print (result)
#helloworld

result = 'Hello' +' ' +'World'
print (result)
#hello world
26 changes: 26 additions & 0 deletions Python-String-Basics/string-repatation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#Python String Repetation and swaping Example

a = "Python"

print ( a * 5)

x= "Python"
y= "Shell"

print (x,y)
#python shell


#swaping value x to y and y to x
x,y=y,x
print (x,y)
#Shell Python

# using triple quotes
print('''Hello, "What's there?"''')

# escaping single quotes
print('Hello, "What\'s there?"')

# escaping double quotes
print("Hello, \"What's there?\"")
Loading