In our last text we learned how to configure Raspberry Pi. Now we can start working with it.

Raspbian OS is a Linux-based OS. It means you can use the terminal of your Raspberry Pi exactly like a Linux terminal. Let’s consider a few commands that may be helpful when working with your Raspberry Pi.

Commands you may need using Terminal Most used Linux commands PDF

Basic programming with Python.

Your Raspberry Pi already contains the application IDLE, that allows you to write Python code for your Raspberry Pi.

As with any other programming language in Python, you have variables, operators, functions, loops, condition statements, strings, lists and other useful programming instruments.

There are some words that you can’t usually use during programming in any commands, they are called reserved words. The list of reserved words is available via the link. The value can be assigned to the variable with the equal sign “=”. It is important that the value can be assigned to the variables simultaneously in Python. Python supports the following data types:

  • Numbers
  • Strings
  • Lists
  • Tuples
  • Dictionary

Numbers can be:

  • int (integers);
  • long (long integers);
  • float (floating point numbers);
  • complex (complex numbers.

Strings: strings are a set of characters marked with quotation marks. In order to operate with strings the + and * can be used in order to manipulate with several strings or to display a string a few times.

Lists are the sets of data enclosed in square brackets. Data in the lists can be accessed and changed. The elements of the lists are numerated from 0.

Tuple is the set of data enclosed in parentheses and are unavailable for changing. Data in tuples are numerated from 0 like in lists and can be accessed the same way.

Dictionaries are sets of data, similar to tables, and consist of keys and values. Keys can be any Python type, and values can be any Python objects.

Python allows the conversion of data types. In order to do that we can just use the other data type as a function.

Python allows you to use several operators:

  • arithmetical (+, -, *, /, %, **, //);
  • logical (and, or, not);
  • comparison;
  • bitwise (&, |, ^, -, ~, <<, >>);
  • membership (in, not in);
  • assignment operators.Python can perform decision making statements:
    • if statement;

    if expression :

    statement

    • if-else statement;

    if expression :

    statement 1

    else :

    statement 2

    • elif statement;

    if expression 1 :

    statement 1

    elif expression 2 :

    statement 2

    elif statement 3 :

    statement 3

    else :

    statement 4

    • nested if statement.

    if expression 1 :

    statement 1

    if expression 2 :

    statement 2

    elif statement 3 :

    statement 3

    else :

    statement 4

    elif expression 5 :

    statement 5

    else :

    statement 6.

    Loops are the codes that perform some code several times. Loops can be the following types:

    • while loop

    while expression :

    statement 1

    else :

    statement 2

    • for loop

    for iterating number in sequence :

    statement

    • nested loop can be performed with for or while loops:

    for iterating number 1 in sequence :

    for iterating number 2 in sequence :

    statement 2

    statement 1

    while expression 1:

    while expression 2:

    statement 2

    statement 1.

Tags: