ClubEnsayos.com - Ensayos de Calidad, Tareas y Monografias
Buscar

Python basics


Enviado por   •  20 de Marzo de 2022  •  Apuntes  •  1.695 Palabras (7 Páginas)  •  35 Visitas

Página 1 de 7

Apuntes curso de phyton

Dia 1

Ejemplos en la consola**

nota: se usa # para los comentarios

para cerrar un codigo de python se usa excit()

************************************notas***************************

t (AMD64)] on win32

Type "help", "copyright", "credits" or "license" for more information.

>>> 2 x 3

  File "<stdin>", line 1

    2 x 3

      ^

SyntaxError: invalid syntax

>>> 2 * 3

6

>>> 2+3 #adition_suma

5

>>> 3-2  #subtraction_resta

1

>>> 2*3 #multiplication_multiplicacion

6

>>> 3/2 #division

1.5

>>> 3%2 #finding the remainder

1

>>> 3%2 #finding the remainder modulo (%)

1

>>> 2%3

2

>>> 3//2 #floor division operador(//) it removes the remainder

1

>>> 3**3 #exponential operator(**) equivale to 3^3=3x3x3

27

>>> #well done ,now you know how use the python interactive sheel

>>>

*******************notas*******************

interactuar con la consola, para escribir un "string" o texto usaremos comillas, si se trata de una palabra

si es una oracion podemos usar dos comillas y si el texto es muy largo usaremos mas de tres comillas

Ejemplos:

>>> 'cristian'

'cristian'

>>> "practicando en consola phyton"

"practicando en consola Phyton"

>>> ''' texto de ejemplo texto de ejemplo texto de ejemplo texto de ejemplo texto de ejemplo'''

'''texto de ejemplo texto de ejemplo texto de ejemplo texto de ejemplo texto de ejemplo'''

El shell interactivo de Python es bueno para probar y probar pequeños códigos de secuencias de comandos, pero no será para un gran proyecto. En un entorno de trabajo real, los desarrolladores usan diferentes editores de código para escribir códigos. En este desafío de 30 días de programación en Python usaremos código de Visual Studio. Visual Studio Code es un editor de texto de código abierto muy popular.

[pic 1]Una sangría es un espacio en blanco en un texto. La sangría en muchos idiomas se usa para aumentar la legibilidad del código; sin embargo, Python usa la sangría para crear bloques de códigos. En otros lenguajes de programación, los corchetes se utilizan para crear bloques de códigos en lugar de sangría. Uno de los errores comunes al escribir código python es la sangría incorrecta.

Comentarios

Los comentarios son muy importantes para que el código sea más legible y para dejar comentarios en nuestro código. Python no ejecuta partes de comentarios de nuestro código. Cualquier texto que comience con hash (#) en Python es un comentario.

Ejemplo: comentario de una sola línea

    # Este es el primer comentario

    # Este es el segundo comentario

    # Python se está comiendo el mundo

Example: Multiline Comment

Triple quote(comillas) can be used for multiline comment if it is not assigned to a variable

"""This is multiline comment

multiline comment takes multiple lines.

python is eating the world

"""

Data types

In Python there are several types of data types. Let us get started with the most common ones. Different data types will be covered in detail in other sections. For the time being, let us just go through the different data types and get familiar with them. You do not have to have a clear understanding now.

Number

Integer: Integer(negative, zero and positive) numbers Example: ... -3, -2, -1, 0, 1, 2, 3 ...

Float: Decimal number Example ... -3.5, -2.25, -1.0, 0.0, 1.1, 2.2, 3.5 ...

Complex Example 1 + j, 2 + 4j

String

A collection of one or more characters under a single or double quote. If a string is more than one sentence then we use a triple quote.

Example:

'Cristian'

'Finland'

'Python'

'I love teaching'

'I hope you are enjoying the first day of 30DaysOfPython Challenge'

Booleans

A boolean data type is either a True or False value. T and F should be always uppercase.

Example:

    True  #  Is the light on? If it is on, then the value is True

    False # Is the light on? If it is off, then the value is False

List

Python list is an ordered collection which allows to store different data type items. A list is similar to an array in JavaScript.

Example:

[0, 1, 2, 3, 4, 5]  # all are the same data types - a list of numbers

['Banana', 'Orange', 'Mango', 'Avocado'] # all the same data types - a list of strings (fruits)

['Finland','Estonia', 'Sweden','Norway'] # all the same data types - a list of strings (countries)

['Banana', 10, False, 9.81] # different data types in the list - string, integer, boolean and float

Dictionary

A Python dictionary object is an unordered collection of data in a key value pair format.

Example:

{

'first_name':'Asabeneh',

'last_name':'Yetayeh',

'country':'Finland',

'age':250,

'is_married':True,

'skills':['JS', 'React', 'Node', 'Python']

}

Tuple

A tuple is an ordered collection of different data types like list but tuples can not be modified once they are created. They are immutable.

Example:

('Asabeneh', 'Pawel', 'Brook', 'Abraham', 'Lidiya') # Names

...

Descargar como (para miembros actualizados)  txt (11.4 Kb)   pdf (346.4 Kb)   docx (378.4 Kb)  
Leer 6 páginas más »
Disponible sólo en Clubensayos.com