Python Programming for Raspberry Pi, Sams Teach Yourself in 24 Hours
place three single or double quotes in a row to define the end of the string, as shown in this example: Click here to view code ...
code your Python scripts. Using Functions to Manipulate Strings Python’s popularity in working with strings is mostly due to the ...
string value. If you want to use the result in your script, you have to assign it to another variable, as in this example: Click ...
The opposite of splitting out string values into a list is joining them, which you do via the join() function. The join() functi ...
TABLE 10.3 String-Testing Functions The string-testing functions help when you need to validate input data that your scripts rec ...
value that the input() function returns. If the string contains an invalid digit, the script produces a message telling the user ...
>>> string12.find('test', 12, 20) -1 >>> It’s also important to know that the find() function returns only the ...
the v3 format() function formatting codes. If you need to use the Python v2 formatting method, refer to the Python documentation ...
Python replaces the {veggie} named placeholder with the value assigned to the veggie name in the format() expression. If you hav ...
TABLE 10.4 Integer-Formatting Codes There’s nothing tricky about any of these codes. You just include them in the placeholder to ...
Click here to view code image >>> test1 = 10 >>> test2 = 3 >>> result = test1 / test2 >>> pr ...
number before the positional format code. Python then positions the number accordingly within that space area, as you can see he ...
2. The format() function can display decimal values in hexadecimal or binary formats. True or false? 3. What format() function f ...
Hour 11. Using Files What You’ll Learn in This Hour: File types that Python can handle How to open a file Reading a file’s data ...
The Linux directory structure is called an upside-down tree because the top of the directory structure is called the root. Figur ...
11.2. TABLE 11.2 Python Directories for This Book Test yourself here. In Table 11.2, which type of directory reference is used: ...
LISTING 11.2 Using the os Function Click here to view code image 1: pi@raspberrypi ~ $ pwd 2: /home/pi 3: pi@raspberrypi ~ $ pyt ...
TABLE 11.5 The open Function mode Designations For all the options a b and/or a + can be tacked onto the end. For example, the r ...
TABLE 11.6 File Object Methods for File Attributes Going back to the example used in Listing 11.3, you can see in Listing 11.4 t ...
Now that you know how to open a file, you should learn how to read one. Reading files is the next item on this hour’s agenda. Re ...
«
5
6
7
8
9
10
11
12
13
14
»
Free download pdf