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», без необходимости каждый раз заново искать на чём Вы остановились. Поставьте закладку, и сможете в любой момент перейти на страницу, на которой закончили чтение.

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

Интервал:

Закладка:

Сделать

>>> mystring = "hello"

>>> list3 = [1, mystring, 3]

>>> list3

[1, 'hello', 3]

>>> mystring = "world"

>>> list3

[1, 'hello', 3]

Of course, this raises the question of how you copy without references when references are the default. The answer, for lists, is that you use the [:] slice, which you saw earlier. This slices from the first element to the last, inclusive, essentially copying it without refer ences. Here is how that looks:

>>> list4 = ["a", "b", "c"]

>>> list5 = list4[:]

>>> list4 = list4 + ["d"]

>>> list5

['a', 'b', 'c']

>>> list4

['a', 'b', 'c', 'd']

Lists have their own collections of built-in methods, such as sort(), append(), and pop(). The latter two add and remove single elements from the end of the list, with pop() also returning the removed element. For example:

>>> list5 = ["nick", "paul", "julian", "graham"]

>>> list5.sort()

>>> list5

['graham', 'julian', 'nick', 'paul']

>>> list5.pop() 'paul'

>>> list5

['graham', 'julian', 'nick']

>>> list5.append("Rebecca")

In addition, one interesting method of strings returns a list: split(). This takes a character by which to split and then gives you a list in which each element is a chunk from the string. For example:

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

>>> string.split(" ")

['This', 'is', 'a', 'test', 'string']

Lists are used extensively in Python, although this is slowly changing as the language matures.

Dictionaries

Unlike lists, dictionaries are collections with no fixed order. Instead, they have a key (the name of the element) and a value (the content of the element), and Python places them wherever it needs to for maximum performance. When defining dictionaries, you need to use braces ( { }) and colons ( :). You start with an opening brace and then give each element a key and a value, separated by a colon, like this:

>>> mydict = { "perl" : "a language", "php" : "another language" }

>>> mydict

{'php': 'another language', 'perl': 'a language'}

This example has two elements, with keys perland php. However, when the dictionary is printed, we find that phpcomes before perl— Python hasn't respected the order in which they were entered. You can index into a dictionary using the normal code:

>>> mydict["perl"] 'a language'

However, because a dictionary has no fixed sequence, you cannot take a slice, or index by position.

Like lists, dictionaries are mutable and can also be nested; however, unlike lists, you cannot merge two dictionaries by using +. A key is used to locate dictionary elements, so having two elements with the same key would cause a clash. Instead, you should use the update()method, which merges two arrays by overwriting clashing keys.

You can also use the keys()method to return a list of all the keys in a dictionary.

Conditionals and Looping

So far, we have been looking at just data types, which should show you how powerful Python's data types are. However, you simply cannot write complex programs without conditional statements and loops.

Python has most of the standard conditional checks, such as >(greater than), <=(less than or equal to), and ==(equal), but it also adds some new ones, such as in. For example, you can use in to check whether a string or a list contains a given character/element:

>>> mystring = "J Random Hacker"

>>> "r" in mystring

True

>>> "Hacker" in mystring

True

>>> "hacker" in mystring

False

The last example demonstrates how inis case sensitive. You can use the operator for lists, too:

>>> mylist = ["soldier", "sailor", "tinker", "spy"]

>>> "tailor" in mylist

False

Other comparisons on these complex data types are done item by item:

>>> list1 = ["alpha", "beta", "gamma"]

>>> list2 = ["alpha", "beta", "delta"]

>>> list1 > list2

True

list1's first element ( alpha) is compared against list2's first element ( alpha) and, because they are equal, the next element is checked. That is equal also, so the third element is checked, which is different. The g in gammacomes after the d in deltain the alphabet, so gammais considered greater than deltaand list1is considered greater than list2.

Loops come in two types, and both are equally flexible. For example, the forloop can iterate through letters in a string or elements in a list:

>>> string = "Hello, Python!"

>>> for s in string: print s,

...

H e l l o , P y t h o n !

The forloop takes each letter in stringand assigns it to s. The letter is then printed to the screen when you use the print command, but note the comma at the end: this tells Python not to insert a line break after each letter. The "..." is there because Python allows you to enter more code in the loop; you need to press Enter again here to have the loop execute.

The same construct can be used for lists:

>>> mylist = ["andi", "rasmus", "zeev"]

>>> for p in mylist: print p

...

andi

rasmus

zeev

Without the comma after the printstatement, each item is printed on its own line. The other loop type is the whileloop, and it looks similar:

>> while 1: print "This will loop forever!"

...

This will loop forever!

This will loop forever!

This will loop forever!

This will loop forever!

This will loop forever!

(etc)

Traceback (most recent call last):

File "", line 1, in ?

KeyboardInterrupt

>>>

That is an infinite loop (it will carry on printing that text forever), so you have to press Ctrl+C to interrupt it and regain control.

If you want to use multiline loops, you need to get ready to use your Tab key: Python handles loop blocks by recording the level of indent used. Some people find this odious; others admire it for forcing clean coding on users. Most of us, though, just get on with programming!

For example:

>>> i = 0

>>> while i < 3:

... j = 0

... while j < 3:

... print "Pos: " + str(i) + "," + str(j) + ")"

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

Интервал:

Закладка:

Сделать

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

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


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

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

x