How to use strings in Python ?
In this post we will see how to use strings in python.
To understand it lets see a sample program and its output.
Working with Strings in Python
user@ngelinux$ cat strings.py #!/usr/local/bin/python3 #### This is python executable path ### First lets print "1. NGELINUX" name = "NGELINUX" #### string variable "name" i=1 #### integer variable "i" print("%d.%s" %(i, name)) #### Printing integer and string variables ### Now lets add .com to it name2=".com" i=i+1 #### incremented i variable by 1. print("%d.Welcome to %s%s" % (i, name, name2)) user@ngelinux$
Output
Lets see the output of above program in python.
user@ngelinux$ ./strings.py 1.NGELINUX 2.Welcome to NGELINUX.com user@ngelinux$
In the similar fashion, we can do integer calculations, use strings and integers together in python.