Variables

 

Variables


📄 Python Script Documentation: Personal Introduction with Variables

Overview:

This Python script demonstrates the use of string variables and different ways to concatenate or format strings for output. It introduces a character named Topsee, presenting his ambitions and current progress.

Code:

# Declaring a variable to store the name

name = "Topsee"

 

# Printing statements using different string concatenation techniques

print("My name is " + name + ".")              # Using string concatenation with '+'

print(f"My name is {name}.")                   # Using f-string (formatted string)

 

# More personalized outputs

print(name + " wants to learn Python.")       

print(name + " wants to go abroad.")          

print(name + " has a big dream.")             

 

# Using a fixed sentence to describe determination

print("He wants to fulfil his dream by hook or by cook

 

# Final statement about current status

print("Now Topu is doing great in his working environment.")


📝 Python Code: Displaying Age and CGPA Information with integer number

Code:

python

CopyEdit

age = 30

CGPA = 3.98

 

print("He is currently", age, "years old.")

print("At the age of", age, ", he has started learning Python.")

print("He will get a CGPA of", CGPA, "in his post-graduation degree.")

Output:

swift

CopyEdit

He is currently 30 years old.

At the age of 30 , he has started learning Python.

He will get a CGPA of 3.98 in his post-graduation degree.


  • You could also use f-strings for a more modern and cleaner format:

python

CopyEdit

print(f"He is currently {age} years old.")

print(f"At the age of {age}, he has started learning Python.")

print(f"He will get a CGPA of {CGPA} in his post-graduation degree.")

 


Key Concepts Used:

  • Variables: The name variable stores a string value that represents a person's name.
  • String Concatenation: Using the + operator to join strings.
  • Formatted Strings (f-strings): A modern and readable way to insert variables into strings.
  • Print Statements: Used to display the output on the console.



Comments

Popular posts from this blog

Python Programming Basic