GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Split lists into new chapter · python043/full-speed-python@2f4b378

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • chapters
    • basic-datatypes.tex
    • lists.tex
  • full-speed-python.tex
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎chapters/basic-datatypes.tex‎

Copy file name to clipboardExpand all lines: chapters/basic-datatypes.tex
+1-48Lines changed: 1 addition & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
\chapter{Basic datatypes}\label{basic-datatypes}
22

3-
In this chapter we will work with the most basic datatypes, numbers, strings and lists. Start your Python REPL and write the following on it:
3+
In this chapter we will work with the most basic datatypes, numbers and strings. Start your Python REPL and write the following:
44

55
\begin{lstlisting}
66
>>> a = 2
@@ -51,37 +51,6 @@ \chapter{Basic datatypes}\label{basic-datatypes}
5151
'HelloHelloHello'
5252
\end{lstlisting}
5353

54-
Finally, Python also supports the list datatype. Lists are data structures that allows us to group some values. Lists can have values of several types and you can also mix different types within the same list although all values are usually of the same datatype.
55-
56-
Lists are created by starting and ending with square brackets and separated by commas. The values in a list can be accessed by its position where 0 is the index of the first value:
57-
58-
\begin{lstlisting}
59-
>>> l = [1, 2, 3, 4, 5]
60-
>>> l[0]
61-
1
62-
>>> l[1]
63-
2
64-
\end{lstlisting}
65-
66-
Can you access the number 4 in the previous list?
67-
68-
Sometimes you want just a small portion of a list, a sublist. Sublists can be retrieved using a technique called \textit{slicing}, which consists on using the start and end indexes on the sublist:
69-
70-
\begin{lstlisting}
71-
>>> l = ['a', 'b', 'c', 'd', 'e']
72-
>>> l[1:3]
73-
['b', 'c']
74-
\end{lstlisting}
75-
76-
Finally, there's also some arithmetic that you can do on lists, like adding two lists together or repeating the contents of a list.
77-
78-
\begin{lstlisting}
79-
>>> [1,2] + [3,4]
80-
[1, 2, 3, 4]
81-
>>> [1,2] * 2
82-
[1, 2, 1, 2]
83-
\end{lstlisting}
84-
8554

8655
\section{Exercises with numbers}
8756

@@ -128,19 +97,3 @@ \section{Exercises with strings}
12897
\end{enumerate}
12998

13099
\end{enumerate}
131-
132-
\section{Exercises with lists}
133-
134-
Create a list named "l" with the following values ([1, 4, 9, 10, 23]). Using the Python documentation about lists (\url{https://docs.python.org/3.5/tutorial/introduction.html#lists}) solve the following exercises:
135-
136-
\begin{enumerate}
137-
138-
\item Using list slicing get the sublists [4, 9] and [10, 23].
139-
140-
\item Append the value 90 to the end of the list "l". Check the difference between list concatenation and the "append" method.
141-
142-
\item Calculate the average value of all values on the list. You can use the "sum" and "len" functions.
143-
144-
\item Remove the sublist [4, 9].
145-
146-
\end{enumerate}
Collapse file

‎chapters/lists.tex‎

Copy file name to clipboard
+49Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
\chapter{Lists}\label{lists}
2+
3+
Python lists are data structures that group sequences of elements. Lists can have elements of several types and you can also mix different types within the same list although all elements are usually of the same datatype.
4+
5+
Lists are created using square brackets and the elements separated by commas. The elements in a list can be accessed by their positions where 0 is the index of the first element:
6+
7+
\begin{lstlisting}
8+
>>> l = [1, 2, 3, 4, 5]
9+
>>> l[0]
10+
1
11+
>>> l[1]
12+
2
13+
\end{lstlisting}
14+
15+
Can you access the number 4 in the previous list?
16+
17+
Sometimes you want just a small portion of a list, a sublist. Sublists can be retrieved using a technique called \textit{slicing}, which consists on defining the start and end indexes:
18+
19+
\begin{lstlisting}
20+
>>> l = ['a', 'b', 'c', 'd', 'e']
21+
>>> l[1:3]
22+
['b', 'c']
23+
\end{lstlisting}
24+
25+
Finally, arithmetic with lists is also possible, like adding two lists together or repeating the contents of a list.
26+
27+
\begin{lstlisting}
28+
>>> [1,2] + [3,4]
29+
[1, 2, 3, 4]
30+
>>> [1,2] * 2
31+
[1, 2, 1, 2]
32+
\end{lstlisting}
33+
34+
35+
\section{Exercises with lists}
36+
37+
Create a list named "l" with the following values ([1, 4, 9, 10, 23]). Using the Python documentation about lists (\url{https://docs.python.org/3.5/tutorial/introduction.html#lists}) solve the following exercises:
38+
39+
\begin{enumerate}
40+
41+
\item Using list slicing get the sublists [4, 9] and [10, 23].
42+
43+
\item Append the value 90 to the end of the list "l". Check the difference between list concatenation and the "append" method.
44+
45+
\item Calculate the average value of all values on the list. You can use the "sum" and "len" functions.
46+
47+
\item Remove the sublist [4, 9].
48+
49+
\end{enumerate}
Collapse file

‎full-speed-python.tex‎

Copy file name to clipboardExpand all lines: full-speed-python.tex
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
\include{chapters/introduction}
5656
\include{chapters/installation}
5757
\include{chapters/basic-datatypes}
58+
\include{chapters/lists}
5859
\include{chapters/functions}
5960
\include{chapters/loops}
6061
\include{chapters/dictionaries}

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.