Introduction to Python

Cards (37)

  • Python is not preinstalled in a Windows OS and needs to be downloaded from https://www.python.org/downloads/ (go for the latest version).
  • When installing Python, it's important to check the box that says Add Python to PATH so that it will automatically edit the environment variables.
  • After installing Python, it's time to choose an IDE, with popular choices including VS Code and PyCharm.
  • Functions in Python can have default arguments, meaning if a parameter is not provided, it will resort on using the default value set in the function definition.
  • Defining a function in Python requires the keyword def followed by the function name, a pair of parentheses that will contain the parameters passed on the function and a colon.
  • Functions in Python are different from C++ and Java, sharing some similar concepts such as defining, calling and returning values.
  • In Python, functions can return multiple values, which can be separated by a comma.
  • Calling a function in Python needs the name of the function in parentheses and the function arguments within.
  • For VS Code, you need to install the plugin needed for running Python apps.
  • PyCharm is specifically used for Python apps.
  • The Community edition of PyCharm is free of charge.
  • If you want a reliable online IDE for Python, I recommend using Google Colab.
  • Unlike Java and C++, Python does not require you to state the variable type, such as int, bool, String, char, etc.
  • In Python, you assign a variable name, followed by a = sign and finally its value to assign value to said variable.
  • In Python, after assigning a value to a variable, you can also reassign new values to the existing variables.
  • Java and C++ also use logical operators, but the way they are implemented with regards on coding is different in Python.
  • Ternary conditional expressions can be used in Python to assign a value to a variable based on a condition.
  • Most of the comparison operators in Python are the same as those used in Java/C++ languages.
  • Python uses the equal to comparison operator to check if x is equal to 10.
  • Nested conditionals are possible in Python, allowing you to check more cases inside a conditional statement.
  • Python provides logical operators (and, or, not) that allow you to combine multiple conditions in a single if statement.
  • Python uses various comparison operators to check conditions, such as == (equal), != (not equal), < (less than), > (greater than), <= (less than or equal to), and >= (greater than or equal to).
  • Python allows the use of the ELSE statement, which is executed if all conditions in the IF and many ELIFs are FALSE.
  • In Python, the keyword and is used to support AND logic, or for the OR gate, and not for the NOT (negate gate).
  • If the condition in the IF statement in Python is TRUE, then it will execute the code inside or within the scope of your IF statement.
  • The output of Python's conditional statements is either TRUE or FALSE.
  • The IF statement in Python is used to test a condition, only one.
  • The IF statement in Python is the first conditional statement you’ll encounter every time you learn a new programming language that supports conditionals.
  • One example of a condition in Python is: "If the score I got in a major exam is greater than 50, then I pass the test, however if I got a score below that then I will definitely fail".
  • If the previous if or elif condition(s) in Python are false, it checks the next condition.
  • The ELIF statement in Python allows you to check multiple conditions sequentially.
  • The ELSE statement in Python is provided as a catch.
  • Python's conditional statements enable you to execute different codes based on the condition you want to evaluate first.
  • Python has conditional capabilities to handle cases for specific problems, algorithms, and decision making.
  • In Python, you can assign a different type to the assigned type of the variable, for example, assigning a String value to the variable myNumber even though it already has an integer assigned to it.
  • Python provides a default value to the parameter greeting, so that whenever a function does not provide a specified parameter, it will resort on "Hello" instead.
  • In Python, you can add up two integer variables and assign a new value to numTotal.