PY1. Introduction to Python

Search for a command to run...

No comments yet. Be the first to comment.
Learn Python step by step with my easy-to-follow blog series. I'll show you how to use Python for all sorts of cool things, from making games to automating everyday tasks.
Introduction NumPy (or Numpy) is a Linear Algebra Library for Python, the reason it is so important for Data Science with Python is that almost all of the libraries in the PyData Ecosystem rely on NumPy as one of their main building blocks. Numpy is ...
Step 1: Accessing the AWS Amplify Console Our journey begins in the AWS Management Console. To start, first choose a Region. This is an important decision as it determines the location of your application's infrastructure. Consider factors like your ...

[A1] - Brute Force Time: O(n^2) Space: O(n^2) class Solution: def generate(self, numRows: int) -> List[List[int]]: # Initialize the triangle with the first row pascal_triangle = [] for i in range(numRows): # S...

YouTube Video https://youtu.be/hfN4VONP4HQ [A1] - Brute Force Time: O(n^2) Space: O(1) class Solution: def twoSum(self, nums: List[int], target: int) -> List[int]: for i in range(len(nums)): for j in range(i+1, len(nums)): ...

LeetCode's Valid Anagram problem checks if two strings, `s` and `t`, are anagrams by comparing character frequencies.

LeetCode's Contains Duplicate problem checks if there are any duplicate elements in a given array, often solved using hash sets or sorting.

Python is a popular programming language. It was created by Guido van Rossum, and released in 1991. It is used for web development (server-side), software development, mathematics, and system scripting. Python is a dynamic, interpreted (byte code-compiled) language. There are no type declarations of variables, parameters, functions, or methods in the source code. This makes the code short and flexible, and you lose the compile-time type checking of the source code. Python tracks the types of all values at runtime and flags code that does not make sense as it runs.
Most programmers start their programming journey by printing “Hello, World!” in the console. It is so popular that now it has become a tradition. So, we will also start by running the Hello World program.
>>> print("Hello, World!")
Hello, World!
Here print() is a function and "Hello, World!". We are passing the string through the print()
function and the function prints the given string in the display.
Python’s syntax is so much more readable. It was designed for readability and has some similarities to the English language with influence from mathematics.
Python syntax can be executed by writing directly in the Command Line:
>>> print("Hello, World!")
Hello, World!
Or by creating a Python file on the server, using the .py file extension, and running it in the Command Line:
C:\Users\Your Name>python myfile.py
Unlike some other programming languages, python uses indentation to indicate a block of code.
If you write this code, you will get an error:
if 5 > 2:
print("Five is greater than two!")
Because this code is not properly indented. The number of spaces that you want to give is totally up to you. Giving 4 spaces is a good practice. You also make sure that you are not doing unnecessary indentation otherwise again you will get an error.
if 5 > 2:
print("Five is greater than two!")
print("Five is greater than two!")
Sometimes you need to add some text to your code to describe how your code is working. In that case, you have to use the proper commenting rule. Comments start with a #, and Python will render the rest of the line as a comment:
#This is an example of a comment
#This is a comment
print("Like and share this post")
Comments can also be placed at the end of a line, and Python will ignore the rest of the line:
print("Like and share this post") #This is an example of a comment
You can also comment out multiple lines of code to prevent Python from executing:
#print("Follow Me")
print("Hi there!")
You can add a multi-line string (triple quotes) in your code, and place your comment inside it:
"""
This is a multiline
comment.
"""
print("Hello, World!")