Some important metacharacters

Lesson Details:
June 29, 2020


I: Introduction:

Python is a powerful, multipurpose and in-demand language that can be used to solve a lot of problems in multiple fields. It has gained immense popularity because of the flexibility it provides when it comes to application development. It can be used to develop games, automation, web apps and even desktop applications.

II: Body:

PYTHON METACHARACTERS:

(a) Indentation:

Like many other languages Python also uses indentation to define blocks and loops. To be specific you need to start at the beginning of the line and keep pressing the Tab key until you reach the end of the block and it will automatically indent your code accordingly. If you want to create a multi-line comment then put two hash signs just before the comment.

# this is a single line comment # # and this is a multi-line comment

(b) Whitespace:

Like any other programming language it does not allow using extra whitespace unless required otherwise. However, you can use blank lines between blocks of code for better readability. You can also use tabs instead of spaces for indentation. However, I would recommend sticking to spaces for indentation as it makes it easier for future developers to understand your code.

(c) Functions:

Functions are one of the most important elements in any language. Python allows you to define functions using def keyword followed by the name of your function, input parameters separated by commas and then finally the body of the function enclosed in curly braces {}. By default, functions created by you do not accept any input parameters unless you specifically define them inside the function parameters list. You can also define default values for these parameters if you want to. Let’s take a look at some sample function definition below:

def print_name ( name , surname ): print ( "Hello %s %s" % ( name , surname )) print_name ( "John" , "Doe" ) # Hello John Doe print_name ( "John" ) # Hello John print_name ( "John" , surname = "Doe" ) # Hello John Doe print_name ( "John" , surname = "Doe" , name = "John" ) # Hello John Doe print_name () # No arguments are given so it prints nothing print_name () # No arguments are given so it prints nothing print_name () # No arguments are given so it prints nothing print_name () # No arguments are given so it prints nothing

(d) Strings:

Strings are immutable objects in python which means they cannot be modified once created. They are one of the most common data types used in almost every application. A string starts with double quotes “” or triple quotes “’’ or apostrophe ‘’’. To escape double quotes within a string, use another double quote “like this”. To escape apostrophe within a string use another apostrophe ‘like this’. You can also use backslash before either double or single quotes to escape them with their respective values. Let’s take a look at some sample string definition below:

my_string = "Python is an easy to learn language" my_string2 = "This is " escaped " string." my_string3 = 'This is ' escaped ' string.' my_string4 = """This is 3 double quotes""" my_string5 = 'An apostrophe may be escaped with another apostrophe' my_string6 = """It's triple quotes""" my_string7 = """It's triple quotes inside triple quotes""" my_string8 = """It's triple quotes inside triple quotes inside quadruple quotes""" my_string9 = """It's triple quotes inside triple quotes inside quadruple quotes inside octuple quotes""" my_string10 = """It's triple quotes inside triple quotes inside quadruple quotes""" my_string11 = """It's triple quotes inside triple quotes""" my_string12 = """It's triple quotes inside triple quotes""" my_string13 = """It's triple quotes""" my_string14 = """It's double quotes""" my_string15 = "It's apostrophe '"

III: Conclusion:

loader
Course content