Introduction to Python Programming Language (Part 1: Variables and Data Types)

This micro-module aim to be a short crash-course to introduce first year students at CUHK Faculty of Engineering and also for those who have never study any programming language (like C, C++, Java, Matlab) before to the fundamentals of Python programming language. 

 

Programming is an important part of our everyday lives.

For example, almost every day you would pass a traffic light and see the traffic light color change from red to yellow and green.

 

Would you like to know how Python programming language is use to manage the traffic light?

 

Pass the course and start your journey to become a real Python hero!

 

 

 

 

History

A Bit of History

Python is a high level, object oriented and general purpose programming language created by Guido Van Rossum. 

Guido named the language after the BBC show "Monty Python's Flying Circus".  Python was first released to public in 1991. 



    Photo: Guido Van Rossum, Wikimedia Commons


High level here means the program is designed to be a computer language that can be easily understood by humans. Python has been praised by many for its elegant syntax and readable code, which make it easy for people who just about to learn and begin their journey in programming.  



What kind of application that Python can build? 

Well, many of you must have been heard of this term before: "The sky is the limit". That could be quite true with this programming language. 

With Python we can develop various applications from: 

  1. Mobile application 
  2. Web application 
  3. GUI development 
  4. System administration 
  5. Financial calculation and resource planning
  6. Data analysis 
  7. Software development 
  8. Games, and many more. 


Here are some of the world’s top organizations that use Python in their operations: 

  • AstraZeneca,
  • D-Link,  
  • Dropbox.
  • Google,  
  • Honeywell, 
  • IBM, 
  • Lucas Film, 
  • Mozilla,
  • NASA, 
  • Phillips, 
  • Reddit, 
  • Walt Disney 

Python Variables

What are Variables in Python?

Variables


Variables are reserved memory locations that are used to store data and information in the programs. 

Variables are also used to access information as well as to manipulate that information. 

Identifiers


The names that we give to identify or declare the value or variables are called identifiers.



Syntax to define a variable value:

variable_name = value

                                           

                                                             Example:       studio_code = 34345                                                                                                   newyear = 01012018

 

Rules for variables

 

 

The following are the rules for declaring a valid variable value:


  • A variable can only start with an alphabet or an underscore ( _ )                                                             

Example:         studio_var → valid variable                                                                                                                                                      3studio → not valid variable 

  • A variable can only contain alphabets ( case sensitive - lower-case: a - z  and upper-case:  A - Z ), digits ( 0 - 9 ) and underscores ( _ )
  • A variable can be of any length
  • A variable cannot be one of the reserved words that Python uses for specific task in the program


Python Reserved Keywords

The following is list of reserved keywords in Python 3:

 

 

 

 

 

Python Data Types

Data Types

In general, data types are the different values that we input to identify the variables.

 

 

The standard classification of data types in Python is as follow:

 

 

 

We will learn more details of these types of data on the next module.

Hooray! Here you are!

Congrats on passing a course on percentages! 

Don't forget to check out this introduction coding exercise worksheet below from Code Club, print and bring them to the class. Enjoy and have fun coding with Python.

about-me_coding exercise_by Code Club

Well done class.

You all did a great job and Welcome to CUHK Python Club! 

 

 

Quiz

1. Who is the creator of Python programming language?

Python is a high level, object oriented and general purpose programming language created by Guido Van Rossum. Guido named the language after the BBC show "Monty Python's Flying Circus".  Python was first released to public in 1991.



Image: Monthy Python's Flying Circus poster - BBC


  • Bill Gates
  • Guido Van Rossum
  • Bjarne Stroustrup
  • Steve Wozniak
  • Dennis Mac Alistair Ritchie

2. Statement: Strings, numbers, list are part of Python data types.

  • True
  • False

3. Match the following Python reserved keywords.

  • continue
    reserved
  • global
    reserved
  • nonlocal
    reserved
  • local
    not reserved
  • password
    not reserved

4. Identify the following variable value: return = tenpercentage. Which rules of variable does it break?

  • Variables must not start with a digit
  • Variables can only contain letters, digits and underscores
  • Variables can be of any length
  • Variables are case sensitive
  • Variables cannot be reserved words