Basic Syntax and First program in Python
vaibhav lawande
WRITER INFORMATION- Data Analyst | ex-HDFC Bank | Python, SQL, Power BI Expert | Data-Driven Decision Maker | Data Management and Analytics Specialist
Overview
Python is a high-level programming language that is easy to learn and widely used for web development, data analysis, artificial intelligence, and many other applications because of it’s simplicity it is widely used. In this tutorial, we will discuss the basic syntax in Python and how to write your first program in Python.
Basic Syntax in Python:
Example:
#**This is a comment**
print("Hello, Let's begin your Journey for becoming a Data Scientist!")
Example:
mathlete = 5 #variable
deepdiver = "Andrew Ng" #variable
print(mathlete)
print(deepdiver)
There are several built-in data types in Python, including:
Example:
mathmogul = 5 # integer
numeralninja = 2.5 # float
brainbooster = "AlmaBetter" # string
boolean = True # boolean
print(type(mathmogul))
print(type(numeralninja))
print(type(brainbooster))
print(type(boolean))
Example:
print(5 + 6) # addition
print(4 - 3) # subtraction
print(6 * 5) # multiplication
print(6 / 5) # division
print(7 % 5) # modulus
print(5 ** 3) # exponentiation
print(4 == 2) # equal to
print(4 != 2) # not equal to
print(6 > 4) # greater than
print(5 < 2) # less than
print(6 >= 6) # greater than or equal to
print(3 <= 5) # less than or equal to
print(3 > 2 and 8 < 10) # logical and
print(4 > 6 or 9 < 10) # logical or
print(not(3 > 4)) # logical not
领英推荐
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 on "New Notebook" or open an existing notebook from your Google Drive in which 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:
print("Hello, Future Data Scientist!")
coursework=input("Write text which you want to show to the user in output")
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 the 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 on 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 a few basic concepts like comments, variables, data types, input, and output which are mostly used go write your first program to get started.
KEY TAKEAWAY
HR recruiter at GI services | Data scientist Trainee -Almabetter |Freelance Model Resonance Edventures limited (IIT foundation) ?? || Purvanchal university??????
1 年This was very helpful ,thankyou