Source: Online social media and website

Programming at Python

Entering Expressions into the Interactive Shell

A window with the >>> prompt should appear; that’s the interactive shell. Enter 3 + 3 at the prompt to have Python do some simple math. 

 

String Concatenation and Replication

 

The meaning of an operator may change based on the data types of the values next to it. For example, + is the addition operator when it operates on two integers or floating-point values. However, when + is used on two string values, it joins the strings as the string concatenation operator. Enter the following into the interactive shell:
 
The expression evaluates down to a single, new string value that combines the text of the two strings. However, if you try to use the + operator on a string and an integer value, Python will not know how to handle this, and it will display an error message.


The error message can’t convert 'int' object to str implicitly means that Python thought you were trying to concatenate an integer to the string 'Mango'.

No comments:

Post a Comment