-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStrings_in_Python.py
More file actions
29 lines (22 loc) · 932 Bytes
/
Strings_in_Python.py
File metadata and controls
29 lines (22 loc) · 932 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# Printing a multi-line string using triple quotes.
# The text 'hello' will be on the first line and 'world' on the second line, indented.
print('''hello
world''')
# Assigning the integer 123 to the variable 'number'.
number = 123
# Converting the integer 'number' to a string and then printing it.
# Output will be '123' as a string.
print(str(number))
# Printing the integer value of 'number' directly.
# Output will be 123 as an integer.
print(number)
# Assigning the string 'world' to the variable 'stringname'.
stringname = 'world'
# Assigning the string 'world1' to the variable 'stringname1'.
stringname1 = 'world1'
# Printing the second character ('o') of the string stored in 'stringname'.
# In Python, string indexing starts at 0.
print(stringname[1])
# Concatenating 'stringname' and 'stringname1' with a space in between and printing.
# Output will be 'world world1'.
print(stringname + " " + stringname1)