Skip to content
This repository was archived by the owner on Oct 12, 2023. It is now read-only.

Commit 04eb433

Browse files
author
Juzer Shakir
committed
Displaying text in Python
A demonstration on how to display different types of texts in Python.
1 parent 1cf83b8 commit 04eb433

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

How_to_Python/strings.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
""" Author : Juzer Shakir || Created on 10 Nov 2017 || Last modified on 18 Dec 2017 1:15pm
2+
Topic : How to output string in python"""
3+
"""----------------------------------------------------------------------------------------------------------------------------------------------------------"""
4+
5+
#Assigning a string to a variable
6+
first_name = "Juzer "
7+
middle_name = "Shabbir "
8+
surname = "Shakir "
9+
10+
#then add these variables to a single variable
11+
full_name = first_name + middle_name + surname
12+
13+
#printing name on the screen
14+
print("\nYour full name is \'{}\'.".format(full_name))
15+
16+
#name will be printed multiple times
17+
print("\nYour name will be printed 3 times ",full_name * 3)
18+
19+
#printing out file location in python
20+
print("\nPrinting the path of this file")
21+
#since file location has '\' in the path name, it has different meaning in python
22+
#we type 'r' before we start a string with file location
23+
#we type 'r' so that it doesn't apply '\' characteristics and knows it's a file location to print
24+
print(r"How_to_Python\strings.py")
25+
print("\n")
26+
27+
#the 'len' function calculates the lenght of a string
28+
print ("The lenght of my name ",len(full_name))
29+
print("\n")
30+
31+
#slicing strings
32+
#we can print from where to where the characters should be printed of the variable
33+
#prints from start to the 3th character of the string
34+
print(first_name[:3])
35+
#prints from 3rd character to the last character of the string
36+
print(middle_name[2:])
37+
#prints from start to the 4th character of the string
38+
print(surname[0:4])
39+
print("\n")
40+
#print from start to the end character of the string
41+
print(full_name[:])
42+
43+
44+
#That's it!
45+
print("\nThe END!")

0 commit comments

Comments
 (0)