Exercise 3.6.9: 24 vs. "24"5 points

Using the correct data type is important when math operators are involved.


Strings can also be “added” together. This is called concatenation.


A substring is part of an existing string. When strings are concatenated, each separate substring is combined to create a new string. Let’s check this out!


In this exercise, change the variables in the second code segment to strings and run the code. What do you notice?

# Code Segment One - Data Type - numbers
num_result = 24 + 24
print(num_result)

# Code Segment Two - Data Type - Strings
# Change both numbers to strings and run code
# Change only one number to a string and run code. What happens?
string_result = 24 + 24
print(string_result)
python

Respuesta :

This is all you need to do for this one add quotes around the number to make it a string. Then for the question I don't know if you need to answer it but I said that when there is only one string it creates and addition problem of 24 + 24 and then when there are two strings it puts them right next to each other making it look like the number 2424.

Ver imagen aaronjduffin
Ver imagen aaronjduffin

The string in Python is indeed an unchangeable data type. A Unicode character is sequentially wrapped in single, double, or triple quotes. In Python, a whole number is null, negatively or positively ironclad, and has unlimited precise accuracy, such as 0, 100, -10.

Program Explanation:

  • In this code two-variable "num_result  and string_result" is defined in which one is a string and one is an integer.
  • In the integer and string variable, it adds two integer values with the "+" symbol.
  • So, it will print the value that is "48" and "24 + 24".

Program:

num_result = 24 + 24#defining an integer variable that use 2 integer value with "+" symbol

print(num_result)#print adding value

string_result = "24 + 24"#defining a string variable that use 2 integer value with "+" symbol

print(string_result)#print string value

Output:

Please find the attached file.

Learn more:

brainly.com/question/18494749

Ver imagen codiepienagoya