❌

Reading view

There are new articles available, click to refresh the page.

Day 1

For the initial refresh of my Python Programming started with the print statements, format, float/string display, concatenation (with/out space), displaying special character (such as \ (backslash), " (double-quotes))

For all the the programming execution used the online compilers (link: https://www.programiz.com/python-programming/online-compiler/)

My PC also having Python 3.12.x

PS C:\Users\usr> python --version
Python 3.12.3

----- below is some sample experiments and its coding part -----

*How do you print the string β€œHello, world!” to the screen?
*

print("Hello, world!")

*How do you print the value of a variable name which is set to β€œSyed Jafer” or Your name?
*

name="First Second"
print("Name: ", name)

*How do you print the variables name, age, and city with labels β€œName:”, β€œAge:”, and β€œCity:”?
*

name="First Second"
age=25
City="Current Place"
print("Name:", name)
print("Age:", age)
print("City:", City)

*How do you use an f-string to print name, age, and city in the format β€œName: …, Age: …, City: …”?
*

name="First Second"
age=25
City="Current Place"
print(f"Name:", name)
print(f"Age:", age)
print(f"City:", City)

*How do you concatenate and print the strings greeting (β€œHello”) and target (β€œworld”) with a space between them?
*

`greeting="Hello"
target="world"

print(greeting, target)`

*How do you print three lines of text with the strings β€œLine1”, β€œLine2”, and β€œLine3” on separate lines?
*

text1="Line1"
text2="Line2"
text3="Line3"
print(text1+"\n"+text2+"\n"+text3)

*How do you print the string He said, "Hello, world!" including the double quotes?
*

print(f"\"Hello World\"")

*How do you print the string C:\Users\Name without escaping the backslashes?
*

print(f"c:\\Users\\Name")

*How do you print the result of the expression 5 + 3?
*

result=5+3
print(result)

*another way
*

print(5+3)

*How do you print the strings β€œHello” and β€œworld” separated by a hyphen -?
*

print(f"hello"+"-"+"world")

*How do you print the string β€œHello” followed by a space, and then print β€œworld!” on the same line?
*

print(f"Hello", "World!")

*How do you print the value of a boolean variable is_active which is set to True?
*

is_active=True
print(is_active)

*How do you print the string β€œHello ” three times in a row?
*

print(3*"Hello")

*How do you print the sentence The temperature is 22.5 degrees Celsius. using the variable temperature?
*

temperature=22.5
print("The temperature is", temperature, "degrees Celsius")

*How do you print name, age, and city using the .format() method in the format β€œName: …, Age: …, City: …”?
*

name="First Second"
age=25
city="Current living"
print("Name: {}, Age: {}, City: {}".format(name, age, city))

*How do you print the value of pi (3.14159) rounded to two decimal places in the format The value of pi is approximately 3.14?
*

pi = 22/7 #3.14159
print("Normal display as float", pi)
print("The value of pi after 2 decimal truncated using format is {:.2f}".format(pi))

*How do you print the words β€œleft” and β€œright” with β€œleft” left-aligned and β€œright” right-aligned within a width of 10 characters each?
*

`left="Left-aligned"
right="Right-Aligned"

print("Left: {:.10s} Right: {:.10s}".format(left, right))`

❌