Andrew Hudson - Fedora™ Unleashed, 2008 edition

Здесь есть возможность читать онлайн «Andrew Hudson - Fedora™ Unleashed, 2008 edition» весь текст электронной книги совершенно бесплатно (целиком полную версию без сокращений). В некоторых случаях можно слушать аудио, скачать через торрент в формате fb2 и присутствует краткое содержание. Город: Indianapolis, Год выпуска: 2008, ISBN: 2008, Издательство: Sams Publishing, Жанр: ОС и Сети, на английском языке. Описание произведения, (предисловие) а так же отзывы посетителей доступны на портале библиотеки ЛибКат.

Fedora™ Unleashed, 2008 edition: краткое содержание, описание и аннотация

Предлагаем к чтению аннотацию, описание, краткое содержание или предисловие (зависит от того, что написал сам автор книги «Fedora™ Unleashed, 2008 edition»). Если вы не нашли необходимую информацию о книге — напишите в комментариях, мы постараемся отыскать её.

Quick Glance Guide
Finding information you need is not always easy. This short index provides a list of common tasks discussed inside this book. Browse the table of contents or index for detailed listings and consult the specified chapter for in-depth discussions about each subject.
left How Do I…?
See…
How Do I…?
See…
left Back up my system?
Chapter 13
Partition a hard drive?
Appendix B, Chapters 1, 35
left Build a new Linux kernel?
Chapter 36
Play MP3s and other music?
Chapter 7
left Burn a CD?
Chapter 7
Print a file?
Chapter 8
left Change a password?
Chapter 4
Read a text file?
Chapter 4
left Change the date and time?
Chapter 32
Read or send email?
Chapter 21
left Compress a file?
Chapter 13
Read or post to newsgroups?
Chapter 5
left Configure a modem?
Chapter 2
Reboot Fedora?
Chapter 1
left Configure a printer?
Chapter 8
Rescue my system?
Chapter 13
left Configure a scanner?
Chapter 7
Set up a DNS server?
Chapter 23
left Configure a sound card?
Chapter 7
Set up a firewall?
Chapter 14
left Configure my desktop settings?
Chapter 3
Set up a web server?
Chapter 15
left Connect to the Internet?
Chapter 5
Set up an FTP server?
Chapter 20
left Control a network interface?
Chapter 14
Set up Samba with SWAT?
Chapter 19
left Copy files or directories?
Chapters 13, 32
Set up wireless networking?
Chapter 14
left Create a boot disk to boot Fedora?
Chapter 1
Shut down Fedora?
Chapter 1
left Create a database?
Chapter 16
Use a spreadsheet?
Chapter 6
left Create a user?
Chapter 4
Use Instant Messaging?
Chapter 5
left Delete a file or directory?
Chapter 32
Watch television on my computer?
Chapter 7
left Get images from a digital camera?
Chapter 7
Edit a text file?
Chapter 4
left Install Fedora?
Chapter 1
Make Fedora more secure?
Chapter 14
left Log in to Fedora?
Chapter 1
Mount a CD-ROM or hard drive?
Chapter 35

Fedora™ Unleashed, 2008 edition — читать онлайн бесплатно полную книгу (весь текст) целиком

Ниже представлен текст книги, разбитый по страницам. Система сохранения места последней прочитанной страницы, позволяет с удобством читать онлайн бесплатно книгу «Fedora™ Unleashed, 2008 edition», без необходимости каждый раз заново искать на чём Вы остановились. Поставьте закладку, и сможете в любой момент перейти на страницу, на которой закончили чтение.

Тёмная тема
Сбросить

Интервал:

Закладка:

Сделать

"Are you really Bill O'Reilly?"

The first example encapsulates the string in single quotation marks and the second and third in double quotation marks. However, printing the first and second strings shows them both in single quotation marks because Python does not distinguish between the two. The third example is the exception — it uses double quotation marks because the string itself contains a single quotation mark. Here, Python prints the string with double quotation marks because it knows the string contains the single quotation mark.

Because the characters in a string are stored in sequence, you can index into them by specifying the character in which you are interested. Like most other languages, these indexes are zero-based, which means you need to ask for character 0 to get the first letter in a string. For example:

>>> string = "This is a test string"

>>> string

'This is a test string'

>>> string[0]

'T'

>>> string [0], string[3], string [20]

('T', 's', 'g')

The last line shows how, with commas, you can ask for several indexes at the same time. You could print the entire first word by using this:

>>> string[0], string[1], string[2], string[3]

('T', 'h', 'i', 's')

However, for that purpose you can use a different concept: slicing. A slice of a sequence draws a selection of indexes. For example, you can pull out the first word like this:

>>> string[0:4]

'This'

The syntax there means "take everything from position 0 (including 0) and end at position 4 (excluding it)." So [0:4]copies the items at indexes 0, 1, 2, and 3. You can omit either side of the indexes, and it copies either from the start or to the end:

>>> string [:4]

'This'

>>> string [5:]

'is a test string'

>>> string [11:]

'est string'

You can also omit both numbers, and it gives you the entire sequence:

>>> string [:]

'This is a test string'

Later you will learn precisely why you would want to do that, but for now there are a number of other string intrinsics that will make your life easier. For example, you can use the +and *operators to concatenate (join) and repeat strings, like this:

>>> mystring = "Python"

>>> mystring * 4

'PythonPythonPythonPython'

>>> mystring = mystring + " rocks! "

>>> mystring * 2

'Python rocks! Python rocks! '

In addition to working with operators, Python strings come with a selection of built-in methods. You can change the case of the letters with capitalize()(uppercases the first letter and lowercases the rest), lower()(lowercases them all), title()(uppercases the first letter in each word), and upper()(uppercases them all). You can also check whether strings match certain cases with islower(), istitle(), and isupper(); that also extends to isalnum()(returns trueif the string is letters and numbers only) and isdigit()(returns true if the string is all numbers).

This example demonstrates some of these in action:

>>> string

'This is a test string'

>>> string.upper()

'THIS IS A TEST STRING'

>>> string.lower()

'this is a test string'

>>> string.isalnum()

False

>>> string = string.title()

>>> string

'This Is A Test String'

Why did isalnum()return false— the string contains only alphanumeric characters, doesn't it? Well, no. There are spaces in there, which is what is causing the problem. More importantly, the calls were to upper()and lower(), and those methods did not change the contents of the string — they just returned the new value. So, to change the string from This is a test stringto This Is A Test String, you actually have to assign it back to the string variable.

Lists

Python's built-in list data type is a sequence, like strings. However, Python's lists are mutable, which means they can be changed. Lists are like arrays in that they hold a selection of elements in a given order. You can cycle through them, index into them, and slice them:

>>> mylist = ["python", "perl", "php"]

>>> mylist

['python', 'perl', 'php']

>>> mylist + ["java"]

['python', 'perl', 'php', 'java']

>>> mylist * 2

['python', 'perl', 'php', 'python', 'perl', 'php']

>>> mylist[1]

'perl'

>>> mylist[1] = "c++"

>>> mylist[1]

'c++'

>>> mylist[1:3] ['c++', 'php']

The brackets notation is important: You cannot use parentheses ( (and )) or braces ( {and }) for lists. Using +for lists is different from using +for numbers. Python detects you are working with a list and appends one list to another. This is known as operator overloading , and it is one of the reasons Python is so flexible.

Lists can be nested, which means you can put a list inside a list. However, this is where mutability starts to matter, and so this might sound complicated! If you recall, the definition of an immutable string sequence is a collection of characters that, after they are set, cannot be changed without creating a new string. Lists are mutable, as opposed to immutable, which means you can change your list without creating a new list.

This becomes important because Python, by default, copies only a reference to a variable rather than the full variable. For example:

>>> list1 = [1, 2, 3]

>>> list2 = [4, list1, 6]

>>> list1

[1, 2, 3]

>>> list2

[4, [1, 2, 3], 6]

Here you can see a nested list. list2contains 4, and then list1, and then 6. When you print the value of list2, you can see it also contains list1. Now, proceeding on from that:

>>> list1[1] = "Flake"

>>> list2

[4, [1, 'Flake', 3], 6]

Line one sets the second element in list1(remember, sequences are zero-based!) to be Flakerather than 2; then the contents of list2are printed. As you can see, when list1changed, list2was updated also. The reason for this is that list2stores a reference to list1as opposed to a copy of list1; they share the same value.

You can show that this works both ways by indexing twice into list2, like this:

>>> list2[1][1] = "Caramello"

>>> list1

[1, 'Caramello', 3]

The first line says, "get the second element in list2 (list1)and the second element of that list, and set it to be 'Caramello'." Then list1's value is printed, and you can see it has changed. This is the essence of mutability: We are changing our list without creating a new list. On the other hand, editing a string creates a new string, leaving the old one unaltered. For example:

Читать дальше
Тёмная тема
Сбросить

Интервал:

Закладка:

Сделать

Похожие книги на «Fedora™ Unleashed, 2008 edition»

Представляем Вашему вниманию похожие книги на «Fedora™ Unleashed, 2008 edition» списком для выбора. Мы отобрали схожую по названию и смыслу литературу в надежде предоставить читателям больше вариантов отыскать новые, интересные, ещё непрочитанные произведения.


Отзывы о книге «Fedora™ Unleashed, 2008 edition»

Обсуждение, отзывы о книге «Fedora™ Unleashed, 2008 edition» и просто собственные мнения читателей. Оставьте ваши комментарии, напишите, что Вы думаете о произведении, его смысле или главных героях. Укажите что конкретно понравилось, а что нет, и почему Вы так считаете.

x