DEV Community

Elizabeth Njoroge
Elizabeth Njoroge

Posted on

Python 101

Python is an interpreted language. Look at it like this, if a person wants to share their code program with someone else so that the other person can run it, if they share the code they wrote, then it's an interpreted language. In python you can create code to a file, then import that file, and the interpreter would read it in real time.

Writing your first code
There's a tradition for every coder while starting to learn python is printing 'Hello, world!'. To do this open vscode and run the code like this; print("Hello, World!")


That's it, your first code is running.

  • Print shows text or values to the user or displays output to the console.
  • () the parenthesis name the inputs the function will use, after it, it tells the Python to run the function.
  • " ', Single or double quotes shows text as a string by enclosing it in quotation marks.

There are basics in python that we will look at;

  1. Variables. A variable refers to a value. More like they are used to store basically any data your program needs. A variable names can only contain numbers, letters and underscores and cannot start with a number hence you cannot use words like; false, none, true, and, as, if, in ,pass etc. Example of a basic variable;

Example of different Variable types;

  1. Data types Data types categorize the kind of values a variable can hold. They include;

-Numeric (int, float), integers are for whole numbers. Float represents decimal numbers, like tracking scores or counting people.

  • Text (str) is used for text, that represents sequence of characters.

  • Boolean (bool), represents truth numbers, that is true or false.

  • Sequence (list, tuple, range). List. They are ordered, mutable collections that can hold items of different types. This meaning their value cannot be changed after creation.

  • Tuple. They are orders, immutable collections defined with parentheses. It is used when the order is important but the contents would not change. For example coordinates.

  • Range. Generates a sequence of numbers.

  • Mapping , stores data as key value pairs.

  • Set. This is collection of unique items and are placed inside curly braces {}.

  • None. It is used where there is absence of value.

  1. Input/Output.
  • Input waits for a user to type something and then return it as a string.

  • Output displays a message.

summary
We have talked about;

  • variables
  • data types
  • input/output.

When people ask why use python it is because of python's ease of learning . Depends on what you do Python is very relevant for data science, computing, and AI.

Top comments (0)