[fusion_builder_container type=”flex” hundred_percent=”no” equal_height_columns=”no” menu_anchor=”” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” class=”” id=”” background_color=”” background_image=”” background_position=”center center” background_repeat=”no-repeat” fade=”no” background_parallax=”none” parallax_speed=”0.3″ video_mp4=”” video_webm=”” video_ogv=”” video_url=”” video_aspect_ratio=”16:9″ video_loop=”yes” video_mute=”yes” overlay_color=”” video_preview_image=”” border_color=”” border_style=”solid” padding_top=”” padding_bottom=”” padding_left=”” padding_right=””][fusion_builder_row][fusion_builder_column type=”1_1″ layout=”1_1″ background_position=”left top” background_color=”” border_color=”” border_style=”solid” border_position=”all” spacing=”yes” background_image=”” background_repeat=”no-repeat” padding_top=”” padding_right=”” padding_bottom=”” padding_left=”” margin_top=”0px” margin_bottom=”0px” class=”” id=”” animation_type=”” animation_speed=”0.3″ animation_direction=”left” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” center_content=”no” last=”true” min_height=”” hover_type=”none” link=”” border_sizes_top=”” border_sizes_bottom=”” border_sizes_left=”” border_sizes_right=”” first=”true”][fusion_text columns=”” column_min_width=”” column_spacing=”” rule_style=”” rule_size=”” rule_color=”” hue=”” saturation=”” lightness=”” alpha=”” user_select=”” awb-switch-editor-focus=”” content_alignment_medium=”” content_alignment_small=”” content_alignment=”” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” sticky_display=”normal,sticky” class=”” id=”” margin_top=”” margin_right=”” margin_bottom=”” margin_left=”” fusion_font_family_text_font=”” fusion_font_variant_text_font=”” font_size=”” line_height=”” letter_spacing=”” text_transform=”” text_color=”” animation_type=”” animation_direction=”left” animation_color=”” animation_speed=”0.3″ animation_delay=”0″ animation_offset=”” logics=””]
Lesson Plan: Python Basic Operators
Overview
This lesson introduces Python’s basic operators, focusing on arithmetic, string, and list operations. You’ll explore how Python adheres to the order of operations, use advanced operators like modulo and exponentiation, and learn how to manipulate strings and lists using operators.
Learning Objectives
- Understand Pythonβs arithmetic operators.
- Apply operators to strings and lists.
- Demonstrate Pythonβs handling of operator precedence.
- Solve real-world problems using operators.
Lesson Content
1. Arithmetic Operators
Python supports standard arithmetic operators: addition (+), subtraction (-), multiplication (*), and division (/). Python also respects the order of operations (PEMDAS: Parentheses, Exponents, Multiplication/Division, Addition/Subtraction).
Example:
[/fusion_text][fusion_syntax_highlighter theme=”” language=”x-sh” line_numbers=”” line_wrapping=”” copy_to_clipboard=”” copy_to_clipboard_text=”” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” class=”” id=”” font_size=”” border_size=”” border_color=”” hue=”” saturation=”” lightness=”” alpha=”” border_style=”” background_color=”” line_number_background_color=”” line_number_text_color=”” margin_top=”” margin_right=”” margin_bottom=”” margin_left=””]bnVtYmVyID0gMSArIDIgKiAzIC8gNC4wCnByaW50KG51bWJlcik=[/fusion_syntax_highlighter][fusion_text columns=”” column_min_width=”” column_spacing=”” rule_style=”” rule_size=”” rule_color=”” hue=”” saturation=”” lightness=”” alpha=”” user_select=”” awb-switch-editor-focus=”” content_alignment_medium=”” content_alignment_small=”” content_alignment=”” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” sticky_display=”normal,sticky” class=”” id=”” margin_top=”” margin_right=”” margin_bottom=”” margin_left=”” fusion_font_family_text_font=”” fusion_font_variant_text_font=”” font_size=”” line_height=”” letter_spacing=”” text_transform=”” text_color=”” animation_type=”” animation_direction=”left” animation_color=”” animation_speed=”0.3″ animation_delay=”0″ animation_offset=”” logics=””]
Prediction: Does Python follow the order of operations? (Yes, it does!)
2. Modulo Operator
The modulo operator (%) returns the remainder of a division.
Example:
[/fusion_text][fusion_syntax_highlighter theme=”” language=”x-sh” line_numbers=”” line_wrapping=”” copy_to_clipboard=”” copy_to_clipboard_text=”” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” class=”” id=”” font_size=”” border_size=”” border_color=”” hue=”” saturation=”” lightness=”” alpha=”” border_style=”” background_color=”” line_number_background_color=”” line_number_text_color=”” margin_top=”” margin_right=”” margin_bottom=”” margin_left=””]cmVtYWluZGVyID0gMTEgJSAzCnByaW50KHJlbWFpbmRlcik=[/fusion_syntax_highlighter][fusion_text columns=”” column_min_width=”” column_spacing=”” rule_style=”” rule_size=”” rule_color=”” hue=”” saturation=”” lightness=”” alpha=”” user_select=”” awb-switch-editor-focus=”” content_alignment_medium=”” content_alignment_small=”” content_alignment=”” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” sticky_display=”normal,sticky” class=”” id=”” margin_top=”” margin_right=”” margin_bottom=”” margin_left=”” fusion_font_family_text_font=”” fusion_font_variant_text_font=”” font_size=”” line_height=”” letter_spacing=”” text_transform=”” text_color=”” animation_type=”” animation_direction=”left” animation_color=”” animation_speed=”0.3″ animation_delay=”0″ animation_offset=”” logics=””]
Result: The remainder when 11 is divided by 3 is 2.
3. Exponentiation Operator
Use double asterisks (**) for exponentiation.
Example:
[/fusion_text][fusion_syntax_highlighter theme=”” language=”x-sh” line_numbers=”” line_wrapping=”” copy_to_clipboard=”” copy_to_clipboard_text=”” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” class=”” id=”” font_size=”” border_size=”” border_color=”” hue=”” saturation=”” lightness=”” alpha=”” border_style=”” background_color=”” line_number_background_color=”” line_number_text_color=”” margin_top=”” margin_right=”” margin_bottom=”” margin_left=””]c3F1YXJlZCA9IDcgKiogMiAgIyA3IHNxdWFyZWQKY3ViZWQgPSAyICoqIDMgICAgIyAyIGN1YmVkCnByaW50KHNxdWFyZWQsIGN1YmVkKQ==[/fusion_syntax_highlighter][fusion_text columns=”” column_min_width=”” column_spacing=”” rule_style=”” rule_size=”” rule_color=”” hue=”” saturation=”” lightness=”” alpha=”” user_select=”” awb-switch-editor-focus=”” content_alignment_medium=”” content_alignment_small=”” content_alignment=”” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” sticky_display=”normal,sticky” class=”” id=”” margin_top=”” margin_right=”” margin_bottom=”” margin_left=”” fusion_font_family_text_font=”” fusion_font_variant_text_font=”” font_size=”” line_height=”” letter_spacing=”” text_transform=”” text_color=”” animation_type=”” animation_direction=”left” animation_color=”” animation_speed=”0.3″ animation_delay=”0″ animation_offset=”” logics=””]
4. String Operators
Python allows operators to work with strings for concatenation and repetition.
Example:
- Concatenation: Combine strings using
+:
[/fusion_text][fusion_syntax_highlighter theme=”” language=”x-sh” line_numbers=”” line_wrapping=”” copy_to_clipboard=”” copy_to_clipboard_text=”” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” class=”” id=”” font_size=”” border_size=”” border_color=”” hue=”” saturation=”” lightness=”” alpha=”” border_style=”” background_color=”” line_number_background_color=”” line_number_text_color=”” margin_top=”” margin_right=”” margin_bottom=”” margin_left=””]aGVsbG93b3JsZCA9ICJoZWxsbyIgKyAiICIgKyAid29ybGQiCnByaW50KGhlbGxvd29ybGQp[/fusion_syntax_highlighter][fusion_text columns=”” column_min_width=”” column_spacing=”” rule_style=”” rule_size=”” rule_color=”” hue=”” saturation=”” lightness=”” alpha=”” user_select=”” awb-switch-editor-focus=”” content_alignment_medium=”” content_alignment_small=”” content_alignment=”” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” sticky_display=”normal,sticky” class=”” id=”” margin_top=”” margin_right=”” margin_bottom=”” margin_left=”” fusion_font_family_text_font=”” fusion_font_variant_text_font=”” font_size=”” line_height=”” letter_spacing=”” text_transform=”” text_color=”” animation_type=”” animation_direction=”left” animation_color=”” animation_speed=”0.3″ animation_delay=”0″ animation_offset=”” logics=””]
Repetition: Repeat strings using *:
[/fusion_text][fusion_syntax_highlighter theme=”” language=”x-sh” line_numbers=”” line_wrapping=”” copy_to_clipboard=”” copy_to_clipboard_text=”” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” class=”” id=”” font_size=”” border_size=”” border_color=”” hue=”” saturation=”” lightness=”” alpha=”” border_style=”” background_color=”” line_number_background_color=”” line_number_text_color=”” margin_top=”” margin_right=”” margin_bottom=”” margin_left=””]bG90c29maGVsbG9zID0gImhlbGxvIiAqIDEwCnByaW50KGxvdHNvZmhlbGxvcyk=[/fusion_syntax_highlighter][fusion_text columns=”” column_min_width=”” column_spacing=”” rule_style=”” rule_size=”” rule_color=”” hue=”” saturation=”” lightness=”” alpha=”” user_select=”” awb-switch-editor-focus=”” content_alignment_medium=”” content_alignment_small=”” content_alignment=”” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” sticky_display=”normal,sticky” class=”” id=”” margin_top=”” margin_right=”” margin_bottom=”” margin_left=”” fusion_font_family_text_font=”” fusion_font_variant_text_font=”” font_size=”” line_height=”” letter_spacing=”” text_transform=”” text_color=”” animation_type=”” animation_direction=”left” animation_color=”” animation_speed=”0.3″ animation_delay=”0″ animation_offset=”” logics=””]
5. List Operators
Lists can also use operators for concatenation and repetition.
Example:
[/fusion_text][fusion_syntax_highlighter theme=”” language=”x-sh” line_numbers=”” line_wrapping=”” copy_to_clipboard=”” copy_to_clipboard_text=”” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” class=”” id=”” font_size=”” border_size=”” border_color=”” hue=”” saturation=”” lightness=”” alpha=”” border_style=”” background_color=”” line_number_background_color=”” line_number_text_color=”” margin_top=”” margin_right=”” margin_bottom=”” margin_left=””]ZXZlbl9udW1iZXJzID0gWzIsIDQsIDYsIDhdCm9kZF9udW1iZXJzID0gWzEsIDMsIDUsIDddCmFsbF9udW1iZXJzID0gb2RkX251bWJlcnMgKyBldmVuX251bWJlcnMKcHJpbnQoYWxsX251bWJlcnMp[/fusion_syntax_highlighter][fusion_text columns=”” column_min_width=”” column_spacing=”” rule_style=”” rule_size=”” rule_color=”” hue=”” saturation=”” lightness=”” alpha=”” user_select=”” awb-switch-editor-focus=”” content_alignment_medium=”” content_alignment_small=”” content_alignment=”” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” sticky_display=”normal,sticky” class=”” id=”” margin_top=”” margin_right=”” margin_bottom=”” margin_left=”” fusion_font_family_text_font=”” fusion_font_variant_text_font=”” font_size=”” line_height=”” letter_spacing=”” text_transform=”” text_color=”” animation_type=”” animation_direction=”left” animation_color=”” animation_speed=”0.3″ animation_delay=”0″ animation_offset=”” logics=””]
Repetition:
[/fusion_text][fusion_syntax_highlighter theme=”” language=”x-sh” line_numbers=”” line_wrapping=”” copy_to_clipboard=”” copy_to_clipboard_text=”” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” class=”” id=”” font_size=”” border_size=”” border_color=”” hue=”” saturation=”” lightness=”” alpha=”” border_style=”” background_color=”” line_number_background_color=”” line_number_text_color=”” margin_top=”” margin_right=”” margin_bottom=”” margin_left=””]cHJpbnQoWzEsIDIsIDNdICogMyk=[/fusion_syntax_highlighter][fusion_text columns=”” column_min_width=”” column_spacing=”” rule_style=”” rule_size=”” rule_color=”” hue=”” saturation=”” lightness=”” alpha=”” user_select=”” awb-switch-editor-focus=”” content_alignment_medium=”” content_alignment_small=”” content_alignment=”” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” sticky_display=”normal,sticky” class=”” id=”” margin_top=”” margin_right=”” margin_bottom=”” margin_left=”” fusion_font_family_text_font=”” fusion_font_variant_text_font=”” font_size=”” line_height=”” letter_spacing=”” text_transform=”” text_color=”” animation_type=”” animation_direction=”left” animation_color=”” animation_speed=”0.3″ animation_delay=”0″ animation_offset=”” logics=””]
Assignment
Create two lists, x_list and y_list, each containing 10 instances of variables x and y, respectively. Then create big_list by concatenating x_list and y_list.
Requirements
- Each list (
x_list, y_list) must contain exactly 10 elements.
big_list must contain 20 elements: 10 x and 10 y.
Code Template:
[/fusion_text][fusion_syntax_highlighter theme=”” language=”x-sh” line_numbers=”” line_wrapping=”” copy_to_clipboard=”” copy_to_clipboard_text=”” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” class=”” id=”” font_size=”” border_size=”” border_color=”” hue=”” saturation=”” lightness=”” alpha=”” border_style=”” background_color=”” line_number_background_color=”” line_number_text_color=”” margin_top=”” margin_right=”” margin_bottom=”” margin_left=””]eCA9IG9iamVjdCgpCnkgPSBvYmplY3QoKQoKIyBUT0RPOiBZb3VyIGNvZGUgaGVyZQp4X2xpc3QgPSBbXQp5X2xpc3QgPSBbXQpiaWdfbGlzdCA9IFtdCgpwcmludCgieF9saXN0IGNvbnRhaW5zICVkIG9iamVjdHMiICUgbGVuKHhfbGlzdCkpCnByaW50KCJ5X2xpc3QgY29udGFpbnMgJWQgb2JqZWN0cyIgJSBsZW4oeV9saXN0KSkKcHJpbnQoImJpZ19saXN0IGNvbnRhaW5zICVkIG9iamVjdHMiICUgbGVuKGJpZ19saXN0KSkKCiMgVGVzdGluZyBjb2RlCmlmIHhfbGlzdC5jb3VudCh4KSA9PSAxMCBhbmQgeV9saXN0LmNvdW50KHkpID09IDEwOgogICAgcHJpbnQoIkFsbW9zdCB0aGVyZS4uLiIpCmlmIGJpZ19saXN0LmNvdW50KHgpID09IDEwIGFuZCBiaWdfbGlzdC5jb3VudCh5KSA9PSAxMDoKICAgIHByaW50KCJHcmVhdCEiKQ==[/fusion_syntax_highlighter][fusion_text columns=”” column_min_width=”” column_spacing=”” rule_style=”” rule_size=”” rule_color=”” hue=”” saturation=”” lightness=”” alpha=”” user_select=”” awb-switch-editor-focus=”” content_alignment_medium=”” content_alignment_small=”” content_alignment=”” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” sticky_display=”normal,sticky” class=”” id=”” margin_top=”” margin_right=”” margin_bottom=”” margin_left=”” fusion_font_family_text_font=”” fusion_font_variant_text_font=”” font_size=”” line_height=”” letter_spacing=”” text_transform=”” text_color=”” animation_type=”” animation_direction=”left” animation_color=”” animation_speed=”0.3″ animation_delay=”0″ animation_offset=”” logics=””]
Answer Key
[/fusion_text][fusion_syntax_highlighter theme=”” language=”x-sh” line_numbers=”” line_wrapping=”” copy_to_clipboard=”” copy_to_clipboard_text=”” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” class=”” id=”” font_size=”” border_size=”” border_color=”” hue=”” saturation=”” lightness=”” alpha=”” border_style=”” background_color=”” line_number_background_color=”” line_number_text_color=”” margin_top=”” margin_right=”” margin_bottom=”” margin_left=””]eCA9IG9iamVjdCgpCnkgPSBvYmplY3QoKQoKIyBTb2x1dGlvbgp4X2xpc3QgPSBbeF0gKiAxMAp5X2xpc3QgPSBbeV0gKiAxMApiaWdfbGlzdCA9IHhfbGlzdCArIHlfbGlzdAoKcHJpbnQoInhfbGlzdCBjb250YWlucyAlZCBvYmplY3RzIiAlIGxlbih4X2xpc3QpKQpwcmludCgieV9saXN0IGNvbnRhaW5zICVkIG9iamVjdHMiICUgbGVuKHlfbGlzdCkpCnByaW50KCJiaWdfbGlzdCBjb250YWlucyAlZCBvYmplY3RzIiAlIGxlbihiaWdfbGlzdCkpCgojIFRlc3RpbmcgY29kZQppZiB4X2xpc3QuY291bnQoeCkgPT0gMTAgYW5kIHlfbGlzdC5jb3VudCh5KSA9PSAxMDoKICAgIHByaW50KCJBbG1vc3QgdGhlcmUuLi4iKQppZiBiaWdfbGlzdC5jb3VudCh4KSA9PSAxMCBhbmQgYmlnX2xpc3QuY291bnQoeSkgPT0gMTA6CiAgICBwcmludCgiR3JlYXQhIik=[/fusion_syntax_highlighter][fusion_text columns=”” column_min_width=”” column_spacing=”” rule_style=”” rule_size=”” rule_color=”” hue=”” saturation=”” lightness=”” alpha=”” user_select=”” awb-switch-editor-focus=”” content_alignment_medium=”” content_alignment_small=”” content_alignment=”” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” sticky_display=”normal,sticky” class=”” id=”” margin_top=”” margin_right=”” margin_bottom=”” margin_left=”” fusion_font_family_text_font=”” fusion_font_variant_text_font=”” font_size=”” line_height=”” letter_spacing=”” text_transform=”” text_color=”” animation_type=”” animation_direction=”left” animation_color=”” animation_speed=”0.3″ animation_delay=”0″ animation_offset=”” logics=””]
Overview of Python Basic Operators
This tutorial introduced Python’s basic operators and demonstrated how they work with numbers, strings, and lists. Key concepts included:
- Arithmetic Operators: Addition (
+), subtraction (-), multiplication (*), and division (/), following Python’s strict adherence to the order of operations (PEMDAS).
- Modulo Operator (
%): Extracts the remainder from division operations.
- Exponentiation (
**): A powerful operator for mathematical calculations like squaring and cubing.
- String Operators:
- Concatenation with
+ to combine strings.
- Repetition with
* to repeat strings.
- List Operators:
- Concatenation of lists with
+.
- Repetition of lists with
*.
Through practical examples and an engaging assignment, you learned how to apply these operators in real-world scenarios.
Wrap-Up
Python’s operators are versatile tools that extend beyond arithmetic, enabling intuitive manipulation of strings and lists. These fundamental building blocks are crucial for programming and serve as the foundation for more advanced topics like operator overloading, matrix operations, and custom objects. With hands-on practice, youβll find yourself seamlessly integrating these operators into your Python projects.
Further Reading/Practice:
- Experiment with mixed operations and parentheses to explore operator precedence.
- Try applying these operators with more complex data structures, like dictionaries and tuples.
[/fusion_text][fusion_text columns=”” column_min_width=”” column_spacing=”” rule_style=”” rule_size=”” rule_color=”” hue=”” saturation=”” lightness=”” alpha=”” user_select=”” awb-switch-editor-focus=”” content_alignment_medium=”” content_alignment_small=”” content_alignment=”” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” sticky_display=”normal,sticky” class=”” id=”” margin_top=”50px” margin_right=”” margin_bottom=”” margin_left=”” fusion_font_family_text_font=”” fusion_font_variant_text_font=”” font_size=”” line_height=”” letter_spacing=”” text_transform=”” text_color=”” animation_type=”” animation_direction=”left” animation_color=”” animation_speed=”0.3″ animation_delay=”0″ animation_offset=”” logics=””]
Related Videos:

Related Posts:
Introduction to JavaScript – Math Operators
Introduction to JavaScript – Review Types and Operators
Coding with JavaScript
Learn about Python Conditions
Introduction to JavaScript – Variables: Mathematical Assignment Operators
Python String Formatting
Learn more about JavaScript Operators
[/fusion_text][/fusion_builder_column][/fusion_builder_row][/fusion_builder_container]