Python Assignment - Print and String in Python
I ran a Python script using the print () function and string variables.
Code:
# Example 1: Basic print statement
print('Hello, world!')
# Example 2: Creating a string using single quotes
String1 = 'Welcome to the Geeks World'
print("String with the use of Single Quotes:")
print(String1)
Output:
Hello, world!
String with the use of Single Quotes:
Welcome to the Geeks World
Explanation:
Hello, world!) and a string stored in a variable.Strings in Python are sequences of characters enclosed in either single quotes (') or double quotes ("). You can use either style, but they must match (open and close the same way).
In this example:
-
I created a string called
String1using single quotes. -
Then I used
print()to output both a label and the string itself.
Together, print() and string variables work perfectly because print() can accept both string literals and string variables as input.
References:
Python 2 String Docs:
Python 3 Print Docs:
Comments
Post a Comment