Bytes

Python Syntax and First program in Python

Python is a high-level programming language that's simple to learn and broadly utilized for web advancement, data analysis, manufactured insights, and numerous other applications. Since of its straightforwardness, it is broadly utilized. This instructional exercise will talk about the essential sentence structure in Python and how to type in your to begin with program in Python

Basic Syntax in Python:

Frame 31-min.png

  1. ūüĎČ Comments in Python are used to explain the Code or make notes for yourself or other developers who may work on the Code in the future. Comments are not executed by the Python interpreter and are ignored during the execution of the program. They start with a #ÔłŹ‚É£ symbol.

Example:

Loading...
  1. Variables: Variables are used in Python to store values ūüíĺ. They allocate memory to a value, making it accessible throughout the program. A variable acts as a container ūüď¶ with a value, which could be a number ūüĒĘ, string ūüĒ§, or list ūüďú.

Example:

Loading...
  1. Data types: Python is powerfully written, which implies you do not have to declare the data type of a variable sometime recently utilizing it, not at all like other languages where we ought to give the data type with the variable name. Python naturally allocates the data type based on the value allotted to the variable. It consequently interprets the data type of a variable.

There are several built-in data types in Python, including:

  1. Numbers ūüĒĘ : We have integers, floating-point numbers, and complex numbers.
  2. Strings ūüďú : A string is a sequence of characters in single or double quotes. It contains the text.
  3. Lists ūüďö : A list is a collection of items that are ordered and changeable.
  4. Tuples ūüĒí : A tuple is very similar to a list but immutable, meaning its values cannot be changed.
  5. Sets ūüßģ : A set is a collection of unique elements.
  6. Dictionaries ūüďĖ : A dictionary is a collection of key-value pairs that are unordered and changeable.
  7. Boolean ‚úÖ : A boolean is a data type with only two values: True or False.

Example:

Loading...
  1. Operators: Python supports several operators, including arithmetic, comparison, and logical operators.

Example:

Loading...

Steps for Python Programming

ūüĎČ Step 1ÔłŹ‚É£: Setting up Google Colab To get started, go to the Google Colab website at ūüĒó https://colab.research.google.com/. You will need to sign in with your Google account. Once you are signed in, you can create a new notebook by clicking "New Notebook" or open an existing notebook from your Google Drive where you want to write Code.

ūüĎČStep 2ÔłŹ‚É£: Writing your first Python program As soon as you click on the new notebook, your colab will appear, where you can see one code cell is already present. In the first cell of the notebook, type the following Code:

Loading...

This is a very simple program that just prints the phrase "Hello, Future Data Scientist!" to the console. Python has a built-in function called "print()" that allows you to output text to the console whereas ‚Äúinput()‚ÄĚ allows to take input from console. These are two functions used for standard input and output in Python.

ūüĎČ Step 3ÔłŹ‚É£: Running your program

To run your program, simply click on the "play" button located on the left side of the cell or press "Shift+Enter" on your keyboard. You should see the output "Hello, World!" printed to the console below the cell.

ūüĎČ Step 4ÔłŹ‚É£:Saving your notebook

To save your notebook, click on "File" in the menu bar and then select "Save" or use the shortcut "Ctrl+S" on Windows or "Cmd+S" on Mac. You can also save your notebook to your Google Drive by clicking on "File" and then "Save a copy in Drive".

ūüĎČ Step 5ÔłŹ‚É£: Sharing your notebook

If you want to share your notebook with others, you can click on "Share" located in the upper-right corner of the notebook. This will allow you to share your notebook via a link or add collaborators who can view or edit your notebook.

Conclusion

Writing your first Python program in Google Colab is a simple and easy process. With Google Colab, you can write, run and share your Python code without having to install any software on your computer. In Python we have few basic concepts like comments, variables,data types, input and output in python which are mostly used go write your first program to get started.

KEY TAKEAWAY

  • The key takeaway from this overview is that Python is a high-level programming language used for web development ūüĆź, data analysis ūüďä, and artificial intelligence ūü§Ė, among other applications.
  • Python has a simple and easy-to-learn syntax ūüďĚ, and it supports several data types and operators.
  • Google Colab is a convenient tool to write ‚úćÔłŹ, run, and share ūü§Ě Python code without having to install any software on your computer.
  • The basic steps for writing a Python program in Google Colab include setting up an account , creating a new notebook ūüďď, writing code ūüíĽ, running the program , saving the notebook ūüíĺ, and sharing it with others ūüĎ•.

QUIZ

  1. What category does Python fall under? 
    1. A low-level programming language 
    2. A high-level programming language 
    3. A markup language 
    4. An operating system

Answer: b: A high-level programming language

  1. What do Python comments mean? 
    1. Code that is executed by the Python interpreter 
    2. Notes for yourself or other developers that are ignored during program execution 
    3. A collection of items that are ordered and changeable 
    4. A data type that can only have two values: True or False

Answer: b: Notes for yourself or other developers that are ignored during program execution

  1. What is the used of variables in Python? 
    1. Storing values 
    2. Executing code 
    3. Commenting on code 
    4. Displaying output

Answer: a: Storing values

  1. What are the data types present in Python? 
    1. Numbers, strings, lists, tuples, sets, dictionaries, booleans 
    2. Integers, floating-point numbers, complex numbers 
    3. Strings 
    4. True or False

Answer: a: Numbers, strings, lists, tuples, sets, dictionaries, booleans

  1. What is the use of operators in Python? 
    1. Built-in functions that allow you to output text to the console 
    2. Code that is executed by the Python interpreter 
    3. Used to perform operations on variables and values 
    4. Notes for yourself or other developers that are ignored during program execution

Answer: c: Used to perform operations on variables and values

Module 1: Getting Started with Python Python Syntax and First program in Python

Top Tutorials

Related Articles

AlmaBetter
Made with heartin Bengaluru, India
  • Official Address
  • 4th floor, 133/2, Janardhan Towers, Residency Road, Bengaluru, Karnataka, 560025
  • Communication Address
  • 4th floor, 315 Work Avenue, Siddhivinayak Tower, 152, 1st Cross Rd., 1st Block, Koramangala, Bengaluru, Karnataka, 560034
  • Follow Us
  • facebookinstagramlinkedintwitteryoutubetelegram

© 2024 AlmaBetter