0% found this document useful (0 votes)
16 views2 pages

Understanding Python Strings

The document introduces string variables in programming, explaining how they can contain text and be 'added' together, which differs from mathematical addition. It includes an exercise for users to create a program that combines their name and Swedish personal number as strings. Additionally, it highlights that strings can include numeric characters, but they are not treated mathematically by the interpreter.

Uploaded by

Vikas Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views2 pages

Understanding Python Strings

The document introduces string variables in programming, explaining how they can contain text and be 'added' together, which differs from mathematical addition. It includes an exercise for users to create a program that combines their name and Swedish personal number as strings. Additionally, it highlights that strings can include numeric characters, but they are not treated mathematically by the interpreter.

Uploaded by

Vikas Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Introduction to Strings

A string variable contains some text. Run the following program:

Note the output. The program shows that you can “add” strings and it’s not the same as
mathematical addition. User input of strings is done using raw_input and input which is for
numbers, see the following program:

Exercise 1
String can also be numbers. Write a program where the user inputs their first name, second
name, and Swedish personal number. The program “adds” these and then prints their name
and personal number in one lines.

Strings can be numbers


A string can include number characters, but the python interpreter does not treat it
mathematically, so using strings 1+1=11 (and not 2).

Computer Experiment 1
Run the following program a few times using different inputs, and note the values of c :

Change raw_input to just input and run the program again, and note the value of c.

You might also like