<jupyter_start><jupyter_text>**Strings**If you want to use text in Python, you have to use a **string.**A **string** is created by entering text between **two single or double quotation masks**> print("Python is fun!")> print('Always look on the bright side of life')The delimiter ("or') used for a string doesn't affect how it behaves in anyway.<jupyter_code>print("Hello world!")<jupyter_output>Hello world!<jupyter_text>**Backslash**Some characters can't be directly included in a string. For instance, double quotes can't be directly included in a double quote string; this would cause it to end prematurely.Characters like these must be escaped by placing a **backslash** before them. Double quotes only need to be escaped in double quote strings, and the same is true for singel quote strings.**For Example:**> print('Brian\'s mother: He\'s not an angel. He\'s a very naughty boy!')**Backslashes** can also be used to escape tabs, arbitraty Unicode characters, and various other things that can't be reliably printed.<jupyter_code>print('Brain\'s mother: He\'s not an angel. He\'s a very naughty boy!') 
print('I\'m learning!')<jupyter_output>I'm learning!<jupyter_text>**Newlines****\n** represents a new line.It can be used in strings to create multi-line output:> print('One \nTwo \nThree')Similarly, **\t** represents a tab.<jupyter_code>print("Hello \nWorld")<jupyter_output>Hello 
World<jupyter_text>**Newlines**Newlines will be automatically added for strings that are created using **three quotes**.**For example**> print(                 """            this            is a             multiline             text            """            )This makes it easier to format long, multi-line texts without the need to explicitly put **\n** for line breaks.<jupyter_code>print("Hi")
print("""This 
is 
great""")
print("Hi \nThis \nis \ngreat")<jupyter_output>Hi 
This 
is 
great<jupyter_text>**Concatenation**As with integers and floats, strings in Python can be added, using a process called **concatenation**, which can be done on any two strings.> print("Spam" + 'eggs')Even if your strings contain numbers, they are still added as strings rather than integers.> print("2" + "2")**Adding** a **string** to a **number** produces an **error**, as even though they might look similar, they are two different entities.<jupyter_code>print("Python " + "is " + "awesome. ")<jupyter_output>Python is awesome.<jupyter_text>**String Operations**Strings can also be **multipled by** **integers.** This produces a **repeated version of the original string**. The order of the string and the integer doesn't matter, but the string usually coms first.> print("spam" *3)> print(4 * '2')Strings can't be multiplied by other strings. Strings also can't be multiplied by floats, even if the floats are whole numbers.<jupyter_code>print(3*'7')<jupyter_output>777<jupyter_text>**Variables**A **variable** allows you to store a value by assigning it to a name, which can be used to refer to the value alter in the program.For example, in game development, you would use a variable to store the points of the player. To assign a variable, use **one equals sign**> user = "James"In given example we assigned string "James" to user variable.<jupyter_code>age = 42

print(age)<jupyter_output>42<jupyter_text>**Variable names**Certain restrictions apply in regard to the characters that may be used in Python variable names. The only characters that are allowed are - **letters,** - **numbers,** and - **underscores.** Also, they can't start with numbers. Not following these rules results in errors.> this_is_a_normal_name = 7> 123abc = 7 SyntaxError: invalid syntaxPython is a case sensitive programming language. Thus, **Lastname** and **lastname** are two **different variable** names in Python.<jupyter_code>A_VARIABLE_NAME = True

if A_VARIABLE_NAME == True:
  print("yes")<jupyter_output>yes<jupyter_text>**Working with Variables**You can use variables to perform corresponding operations, just as you did with numbers and strings:> x = 7> print(x)> print( x + 3)> print(x)As you can see, the variable stores its value throughout the program.<jupyter_code>spam = "eggs"

print(spam*3)<jupyter_output>eggseggseggs<jupyter_text>**Working with Variables**Variables can be reassigned as many times as you want, in order to change their value.**In Python**, variables **don't have specific types**, so you can assign a string to a variable, and later assign an integer to the same variable.> x = 123.456> print(x)> x = "This is a string"> print(x + "!")However, it is not good practice. To avaid mistakes, try to avoid overwriting the same variable with different data types.<jupyter_code>x = 5
y = 7

print(x + y)<jupyter_output>12<jupyter_text>**Input**Let's assume we want to take the age of the user as input. We know that the **input()** function returns a string. To convert it to a number, we can use the **int()** function.> age = int(input())> print(age)Similarly, inorder to convert a number to a string, the "str()" function is used. This can be useful if you need to use a number in string concatenation.For example:> age = 42> print("His age is " + str(age))<jupyter_code>x = "2"
y = "4"
z = int(x) + int(y)
print(z)<jupyter_output>6<jupyter_text>**Input**You can use input() multiple times to take multiple user inputs **For example:**> name = input()> age = input()> print(name + " is " + age)When input() function executes, program flow stops until a user enters some value.<jupyter_code>x = int(input())
y = int(input())

print(x + y)<jupyter_output>7
3
10<jupyter_text>**In-Place Operators****In-place operators** allow you to write code like 'x = x + 3' more concisely, as ' x +=3'.The same thing is possible with other operators such as -, * , /and % as well.> x = 2 > print(x)> x += 3> print(x)<jupyter_code>x = 4
x *=3

print(x)<jupyter_output>12<jupyter_text>**In-place Operators**These operators can be used on types other than numbers, as well, such as **strings**> x = "spam"> print(x)> x += "eggs"> print(x)In-place operators can be used for any numerical operation( + , - , * , / , %, **, //).<jupyter_code>x = "a"
x *= 3

print(x)
spam = "7"
spam = spam + "0"
eggs = int(spam) + 3

print(float(eggs))
#enter '42' as input:

age = int(input())
print(age + 8)
x = 5
y = x +3
y = int(str(y) + "2")

print(y)
x = 4
x += 5

print(x)
x = 3 
num = 17

print(num%x) # 3*5 =15
name = input()

print("Welcome,"+ name)<jupyter_output>john
Welcome,john
{'fraction_non_alphanumeric': 0.12310312790337566, 'fraction_numerical': 0.010529575720037163, 'mean_word_length': 4.909423604757548, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 78, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '14', 'dir': 'jupyter-structured-clean-dedup', 'id': '8669', 'license': 'Apache-2.0', 'n_tokens_mistral': 2066, 'n_tokens_neox': 1950, 'n_words': 822, 'path': 'Py2_Strings_and_Variables.ipynb', 'repo_name': 'niklaust/self_study', 'size': '6458'}