0% found this document useful (0 votes)
20 views9 pages

Python and R Programming Basics Guide

1) The document presents basic concepts of programming in Python and R, including variables, data types, lists, tuples, dictionaries, and operators. 2) Python is introduced as an interpreted open-source programming language, with explanations about variables, data types, and string operations. 3) Concepts of lists, tuples, and dictionaries in Python are also explained, with examples of declaration and functions for manipulating lists.

Translated by

ScribdTranslations
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views9 pages

Python and R Programming Basics Guide

1) The document presents basic concepts of programming in Python and R, including variables, data types, lists, tuples, dictionaries, and operators. 2) Python is introduced as an interpreted open-source programming language, with explanations about variables, data types, and string operations. 3) Concepts of lists, tuples, and dictionaries in Python are also explained, with examples of declaration and functions for manipulating lists.

Translated by

ScribdTranslations
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

AlfaCon Public Competitions

Syllabus
INDEX
Concepts of Python Programming
Python
R Language and R Studio
API – Application Programming Interface
Metadata

Copyright Law No. 9,610, of February 19, 1998: It prohibits the total or partial reproduction of this material or its dissemination with
commercial purposes or not, in any means of communication, including the Internet, without the authorization of AlfaCon Public Competitions.
1
AlfaCon Public Competitions

Basics of Python and R Programming


Python
Python is an interpreted programming language, open source and available for
several operating systems It is said that a language is interpreted if it does not need to be with-
spilled (translated into a machine language), but rather "read" by another program (called
the interpreter) that translates for the machine what your program wants to say
Variables:
In Python, the basic data types are:
→pointer (stores integer numbers);
→tipofloat(stores numbers in decimal format); and
string type (stores a set of characters)
We will also find other types of data such as complex numbers; imaginary numbers
scenarios are written with the suffix 'j' or 'J'

Each variable can store only one data type at a time.


Python is a dynamically typed language. Unlike other programming languages...
In programming, it is not necessary to declare what type each variable will be at the beginning of the program. When you ...

makes an assignment of value, automatically the variable becomes of the type of the stored value, as
presented in the following examples:
Examples:
>>>a=10
>>>a
10
The variable becomes an integer type variable.
Strings can be concatenated (combined) with the + operator, and repeated with *.

>>> email = ’Marciohollweg’ + ’@’ + ’[Link]’


>>> email
’Marciohollweg@[Link]’
>>> curso = ‘ALFA’
<cursocursocurso>
<ALFA ALFA ALFA>
Lists, Tuples, and Dictionaries:
I listed a sequential set of values, where each value is identified by an index.
The first value has index 0. A list in Python is declared as follows:
Nome_Lista = [ valor1, valor2, , valorN]
A list can have values of any type, including other lists.
Copyright Law No. 9,610, of February 19, 1998: Prohibits the total or partial reproduction of this material or dissemination of
commercial or non-commercial purposes, in any means of communication, including the Internet, without the authorization of AlfaCon Public Competitions.

2
AlfaCon Public Competitions

Examples:
>>> L = [3 , “abacate” , 9.7 , [5 , 6 , 3] , “Python” , (3 , ‘j’)]
>>> print(L[2])
9.7
>>> print(L[3])
[5,6,3]
>>>print(L[3][1])
6
FUNCTIONS FOR LIST MANIPULATION
The list is a mutable structure, meaning it can be modified. In the table below, there are
some functions used to manipulate lists
Function Description Example
L = [1, 2, 3, 4]
len Returns the size of the list.
len(L) 4
[10, 40, 30, 20]
min Return the smallest value from the list.
min(L) 10
L = [10, 40, 30, 20]
max Returns the highest value in the list.
max(L) 40
L = [10, 20, 30]
sum Return the sum of the elements in the list.
sum(L) 60
L = [1, 2, 3]
append Add a new value at the end of the list. [Link](100)
L [1, 2, 3, 100]
L = [1, 2, 3, 4]
remove Remove an element from the list, given its index. remove L[1]
L [1, 3, 4]
Tuple, just like List, is a sequential set of values, where each value is identified.
through an index The main difference between them is that tuples are immutable, or
be, your elements cannot be changed
Among the utilities of tuples, packing and unpacking operations stand out.
value mentoring
A tuple in Python is declared as follows:
Name_tuple = (value1, value2, ..., valueN)
Examples:
(1, 2, 3, 4, 5)
>>> print(T)
(1, 2, 3, 4, 5)
>>> print(T[3])
4
A dictionary is a set of values, in which each value is associated with an access key.
A dictionary in Python is declared as follows:
Nome_dicionario = { chave1 : valor1, chave2 : valor2, chave3 : valor3, chaveN : valorN}
Example:
>>>D={“arroz”: 17.30, “feijão”:12.50,”carne”:23.90,”alface”:3.40}
>>> print(D)
{“arroz”: 17.3, “carne”: 23.9, “alface”: 3.4, “feijão”: 12.5}
>>> print(D[“carne”])
Copyright Law No. 9.610, of February 19, 1998: Prohibits the total or partial reproduction of this material or disclosure with
commercial or non-commercial purposes, in any form of communication, including the Internet, without the authorization of AlfaCon Public Competitions.

3
AlfaCon Public Competitions

23.9
SOME OPERATORS
The Python language may present some operators different from the usual ones in other languages:
Mathematical Operators:
Addition + age + 1 = adding 1 to the age
Subtraction - age - 1 = subtracting 1 from the age
Multiplication * value * 10 = multiplying by 10
Division / amount / 10 = dividing the amount by 10
Remaining % number % 3 = giving the remainder of a number divided by 3
Power ** number ** 2 = raising the number to the second power
Relational Operators:
Greater >
Minor
<
Greater than or equal to >=
Less than or equal to <=
Same ==
Different !=
Logical Operators:
OU Or
E
And
Negation
Not
The use of # (hashtag) or ''' (triple quotes) indicates a comment.
CONDITIONAL AND REPETITION STRUCTURES IN PYTHON
In Python, just like in most programming languages, the program must be able to
make decisions based on values and results generated during its execution, that is, it must be capable of
decide whether a certain instruction should or should not be executed according to a conditionTo meet
in this type of situation, we can use special instructions called conditional structures
In addition to these, programming languages typically also support the so-called
loops, structures that allow instructions to be executed repeatedly until a
condition being met
Conditional structures with IF
It establishes a condition structure that allows evaluating an expression and, according to its result...
keep, perform a certain action
In the following code, we have an example of using the if statement, where we check if the variable age is
less than 20. If yes, we display a message on the screen, and if no, the code
will continue normally, disregarding line 3

As we can see, this structure is formed by the reserved word if, followed by a
condition and by two points (:) The lines below it form the block of instructions that will be executed
that condition is met. For this, they must be correctly indented, respecting the
Python specification: In this code, only the instruction in line 3 is executed, and that is why it is
more advanced If other lines needed to be executed in case the age is less than 20,
they should also be at the same indentation level as line 3
We saw earlier how to use 'if' to execute an action if a condition is met.
However, no specific behavior has been defined for the case where the condition does not apply.
be satisfied When this is necessary, we need to use the reserved word else Additionally-
If there is more than one alternative condition that needs to be checked, we should use elif.

Copyright Law No. 9,610, of February 19, 1998: Prohibits total or partial reproduction of this material or its disclosure
commercial or not, in any means of communication, including the Internet, without the authorization of AlfaCon Public Competitions.
4
AlfaCon Public Competitions

evaluate the intermediate expressions before using else


Listing 1 presents a demonstration of these instructions.

Loops with FOR and WHILE

In some situations, it is common for the same instruction (or set of them) to need to be executed.
cut several times in a row. In these cases, we normally use a loop (or repetition loop),
which allows executing a block of code repeatedly, while a given condition is met
In Python, loops are coded using the for and while commands. The first allows us to
to iterate over the items in a collection and, for each of them, execute a block of code. As for while,
executes a set of instructions multiple times while a condition is met
In Listing 2, we have an example of using the for command.

The variable defined on line 1 is a list initialized with a sequence of values of the type
The for loop goes through all these elements, one by one, and in each case, assigns the value
from the item to the variable n, which is printed next. The result is then the printing of all names.
contained in the list, as we see in lines 5 to 7.
The while command, in turn, makes a set of instructions execute while
a condition is met When the result becomes false, the execution is interrupted, exiting
loop, and move to the next block
In the following code, we see an example of using the while loop, where we define the counter variable,
starting with 0, and while its value is less than 5, we execute the instructions in lines 3 and 4

Note that in line 4 we increment the counter variable, so that at some point
its value exceeds 5. When this is confirmed in line 2, the loop will be interrupted. If the
the stopping condition is never reached, the loop will run infinitely, causing problems in
program
Copyright Law No. 9.610, of February 19, 1998: Prohibits the total or partial reproduction of this material or its disclosure with
commercial or not, in any means of communication, including the Internet, without the authorization of AlfaCon Public Competitions.
5
AlfaCon Public Competitions

Control structures, conditionals, and loops are present in most programming languages.
programming represents a fundamental part of each of them. Therefore, it is very im-
It is important to understand the syntax and functioning of these structures.

R Language and R Studio


The R language is used by scientists, statisticians, and more recently, data scientists.
as a convenient means for interactive exploratory data analysis Unlike what is
imagine about the R language, it is not limited to just interactive sessions, because of the fact that
being a programming language, scripts can be created and packaged as libraries
As soluções com base emscriptsfornecem resultados mais consistentes e confiáveis do que os fluxos
traditional work, which requires a large amount of manual interactions with a
graphical user interface
This language is often not considered as a programming language, being
but compared to a specialized statistical product This is a widely discussed topic
when considering data manipulation using Excel spreadsheets or a relational database
The SQL server is used mostly for database management. The R language is more used for manipulating datasets.
of medium size, statistical analyses and the production of documents and presentations centered on
data Besides, it provides us with a wide variety of linear and nonlinear modeling, tests
classical statistics, time series analysis, clustering, in addition to being highly extensible
One of the strengths of R is the ease we can have with better quality regarding
well-designed plots, inclusion of mathematical symbols and formulas, when these are passed
to be necessary, since R is an integrated set of software facilities aimed at the mani-
data sampling and graphical display
Two of the largest companies in the market, Facebook and FourSquare, use the language-
gem R both for recommendations and for modeling user behaviors.
R uses a command line interface, but there are also several graphical front-ends for it.
like R Studio
Appearance of R Studio

Copyright Law No. 9,610, of February 19, 1998: Prohibits the total or partial reproduction of this material or disclosure without
for commercial purposes or not, in any means of communication, including the Internet, without authorization from AlfaCon Public Competitions.

6
AlfaCon Public Competitions

It is composed of 4 parts and each one has a function:


At the top left, there is the script, where we type the commands;
At the bottom left is the console, where the script commands are executed and visualized.
we analyze your results, as well as the statistics;
At the top right are the databases we are working with and some buttons.
that assist in their importation;
At the bottom right, we can see the graphs we are building.

API – Application Programming Interface


The acronym API refers to the English term Application Programming Interface which means in
Application Programming Interface

An API's main objective is to make an application's resources available for use.


by another application, abstracting the implementation details and often restricting access
to these resources with specific rules for such
An API is created when a software company intends for other creators to
software develop products associated with their service. There are several of them available.
send your codes and instructions to be used on other sites in the most convenient way for
its users The Google Maps is one of the great examples in the area of APIs Through its code
original, many other sites and applications use Google Maps data adapting it in the best way
in order to use this service
When a person accesses a hotel's page, for example, it is possible to see within the
own site the Google Maps map to know the location of the establishment and check what the
best way to get there This procedure is performed through an API, in which the
hotel website developers use Google's Maps code to insert it into a determi-
need local for your page
TIPOS DE API
In terms of software development, an API can be built in several ways.
most used are:
→DLL – Dynamic-link library: are executables resulting from classes or sets of classes compiled
in environments like .NET and Delphi, for example, embedded in a DLL, according to the rules of
applied visibility, several methods/functions that can be used by third parties are exposed
Copyright Law No. 9,610, of February 19, 1998: Prohibits the total or partial reproduction of this material or its disclosure without
for commercial purposes or not, in any means of communication, including the Internet, without authorization from AlfaCon Public Competitions.

7
AlfaCon Public Competitions

→Plugins: currently it is one of the most used modes. When we talk about a WordPress blog.
example most of the resources are a result of plugin consumption (examples are the use of decaptcha,
email sending, efeed, antispam, SEO optimizer, statistics analyzer etc.)
WebAPI: basically, they are APIs used in web solutions. WebAPIs can be client-side or
server-side (executed on the front or in the back-end of a web application)

Metadata
The metadata technology emerged due to organizations needing to better understand the
data that they maintain. The metadata provides a concise description of the data.
data can be documents, collection of documents, graphs, tables, images, videos, among others
so many others
In databases, information about the data is just as important as the data.
Relational Database Management Systems - RDBMS also use metadata.
The tables in the database are used to store information. Similarly, a
RDBMS has several metatables that store descriptions of the tables.
In the Oracle DBMS, for example, the USER_TABLES table is a meta table that contains information
actions regarding tables created by users. Among this information, the following can be found:
table owner, table name, tablespace name (logical storage unit) for
which was defined, among others
Metadata play an important role in data management, as they provide information about the data.
are processed, updated and consulted. The information on how the data was created/derived
two, environment in which it lives and/or lived, changes made, among others, are obtained from metadata
Metadata provides the necessary features to understand data over time.

The date and time stamped on the photos also constitute the use of metadata, in addition to the location.
geographic action that modern cameras are capable of performing for each image
Exercises
Regarding languages, judge the following item.
Python is a high-level, object-oriented programming language that is difficult to read, as it does not
allows indentation of code lines
Sure Wrong ( )
Judge the following item regarding the Python language, version 3.1.
02. If, in any line of the Python script, the regular expression coding[=:] \s*([~\w ]+) matches
by a comment, this will be processed as a coding statement.
Sure ( ) Wrong

Copyright Law No. 9,610, of February 19, 1998: Prohibits total or partial reproduction of this material or disclosure of
commercial or not, in any means of communication, including the Internet, without the authorization of AlfaCon Public Contests.
8
AlfaCon Public Competitions

03. The script R presented below generates a certain graph.


c=1:6
x = c(2, 4, 6)
y <- x + c
rev(c) -> k
f=sort(y)
barplot(f)
Is the graph generated by this script?

Sure ( ) Wrong ( )
With the introduction of HTML5, several new Javascript APIs (Application Programming ...
interfaces) were made available, considerably increasing the amount of resources
available for web page production
Sure Wrong ( )
[Link] a DBMS, the data dictionary manager is responsible for storing the metadata.
about the database structure
Sure ( ) Wrong ( )
Template
01 - Wrong
02 - Wrong
03 - Wrong
04 - Right
05 - Right

Copyright Law No. 9,610, of February 19, 1998: Prohibits the total or partial reproduction of this material or dissemination with
commercial or not, in any means of communication, including on the Internet, without the authorization of AlfaCon Public Competitions.
9

You might also like