Lets write a simple program

Helenjoy
4 min readMay 25, 2023

--

print function

In Python, the print() function is used to display output on the console or terminal. It takes one or more arguments and prints them as text.

Here are a few examples of how to use the print() function:

Printing a single value:

print(“Hello, World!”)

Output: Hello, World!

In this example, the print() function displays the string “Hello, World!” as output.

Printing multiple values:

name = “Alice”

age = 25

print(“My name is”, name, “and I am”, age, “years old.”)

Output: My name is Alice and I am 25 years old.

In this example, we pass multiple arguments to the print() function. The values are automatically separated by a space and printed as a single line of output.

Printing with formatting:

score = 98.5

print(“Your score is %.2f” % score)

Output: Your score is 98.50

In this example, we use string formatting to specify the precision of the floating-point number. The % operator is used to insert the value of score into the string, with %.2f indicating that the number should be formatted with two decimal places.

Printing on separate lines:

print(“Line 1”)

print(“Line 2”)

print(“Line 3”)

Output:

Line 1

Line 2

Line 3

In this example, each print() statement prints its respective string on a separate line.

The print() function can be customized further by using different arguments and formatting options. It is a versatile function for displaying output and is commonly used for debugging, displaying results, or providing information to the user.

len() function:

The len() function returns the length of a given object, such as a string, list, or tuple. When applied to a string, it returns the number of characters in the string.

str() function:

The str() function is used to convert an object into its string representation. It takes an argument and returns a string version of that argument.

In the above example, str(age) converts the integer age into a string representation. The resulting string is then concatenated with other strings to form the final output.

The str() function is commonly used when you need to concatenate strings with non-string objects, such as numbers, to form a meaningful output.

These are two useful functions in Python when working with strings: len() for getting the length of a string or object, and str() for converting an object into a string representation.

A program that says our name ,age, length of name ,and next year age :)

In this program, we use the input() function to ask the user for their name and age. The input() function displays the given prompt and waits for the user to enter a value. The values entered by the user are stored in the name and age variables, respectively.

After obtaining the name and age, we use the print() function to display a message that includes the entered name and age.

When you run this program, it will display the prompts asking for the name and age. Once the user enters the values, it will print a greeting message with the name and age provided.

Note that in Python 2.x, the input() function behaves differently. If you’re using Python 2.x, you should use raw_input() instead of input() to achieve the same behavior.

Try out this and feel the happiness .. small steps daily makes long runs easy..

--

--

Helenjoy

Research aspirant in deep learning based video compression