<jupyter_start><jupyter_text>Creating Variables Variables are containers for storing data values.Unlike other programming languages, Python has no command for declaring a variable.A variable is created the moment you first assign a value to it. e.g<jupyter_code>x = 5
y = "John"
print(x)
print(y)<jupyter_output>5
John<jupyter_text>Variables do not need to be declared with any particular type and can even change type after they have been set. e.g<jupyter_code>x = 4 # x is of type int
x = "Sally" # x is now of type str
print(x)<jupyter_output>Sally<jupyter_text>String variables can be declared either by using single or double quotes: e.g<jupyter_code>x = "John"
# is the same as
x = 'John'<jupyter_output><empty_output><jupyter_text>Variable Names A variable can have a short name (like x and y) or a more descriptive name (age, carname, total_volume). Rules for Python variables: e.gLegal variable names: myvar = "John" my_var = "John" _my_var = "John" myVar = "John" MYVAR = "John" myvar2 = "John" Illegal variable names: 2myvar = "John" my-var = "John" my var = "John"  NOTE Variable names are case-sensitive  Assign Value to Multiple Variables Python allows you to assign values to multiple variables in one line: e.g<jupyter_code>x, y, z = "Orange", "Banana", "Cherry"
print(x)
print(y)
print(z)<jupyter_output>Orange
Banana
Cherry<jupyter_text>And you can assign the same value to multiple variables in one line: e.g<jupyter_code>x = y = z = "Orange"
print(x)
print(y)
print(z)<jupyter_output>Orange
Orange
Orange<jupyter_text>Output Variables The Python print statement is often used to output variables.To combine both text and a variable, Python uses the + character: e.g<jupyter_code>x = "Python is "
y = "awesome"
z =  x + y
print(z)<jupyter_output>Python is awesome<jupyter_text>For numbers, the + character works as a mathematical operator: e.g<jupyter_code>x = 5
y = 10
print(x + y)<jupyter_output>15<jupyter_text>If you try to combine a string and a number, Python will give you an error: e.g<jupyter_code>x = 5
y = "John"
print(x + y)<jupyter_output><empty_output><jupyter_text>Global Variables Variables that are created outside of a function (as in all of the examples above) are known as global variables.Global variables can be used by everyone, both inside of functions and outside. e.g -Create a variable outside of a function, and use it inside the functioni.e<jupyter_code>x = "awesome"

def myfunc():
  print("Python is " + x)

myfunc()<jupyter_output>Python is awesome<jupyter_text>If you create a variable with the same name inside a function, this variable will be local, and can only be used inside the function. The global variable with the same name will remain as it was, global and with the original value. e.g  - Create a variable inside a function, with the same name as the global variable<jupyter_code>x = "awesome"

def myfunc():
  x = "fantastic"
  print("Python is " + x)

myfunc()

print("Python is " + x)<jupyter_output>Python is fantastic
Python is awesome<jupyter_text>The global Keyword Normally, when you create a variable inside a function, that variable is local, and can only be used inside that function.To create a global variable inside a function, you can use the global keyword. e.g  - If you use the global keyword, the variable belongs to the global scope:  i.e<jupyter_code>def myfunc():
  global x
  x = "fantastic"

myfunc()

print("Python is " + x)<jupyter_output>Python is fantastic<jupyter_text>*Also, use the global keyword if you want to change a global variable inside a function. e.g - To change the value of a global variable inside a function, refer to the variable by using the global keyword:i.e<jupyter_code>x = "awesome"

def myfunc():
  global x
  x = "fantastic"

myfunc()

print("Python is " + x)<jupyter_output>Python is fantastic
{'fraction_non_alphanumeric': 0.08265547100498556, 'fraction_numerical': 0.0028863815271582263, 'mean_word_length': 5.108974358974359, 'pattern_counts': {'":': 0, '<': 39, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '12', 'dir': 'jupyter-structured-clean-dedup', 'id': '645157', 'license': 'Apache-2.0', 'n_tokens_mistral': 1255, 'n_tokens_neox': 1196, 'n_words': 505, 'path': 'Python Variables.ipynb', 'repo_name': 'Vinaykumargond/Python-Tutorial', 'size': '3811'}