Technology Books 技术书籍 Technologie-Bücher 技術関連書籍 - Home Teachers India

Breaking

Welcome to Home Teachers India

The Passion for Learning needs no Boundaries

Translate

Friday 7 October 2022

Technology Books 技术书籍 Technologie-Bücher 技術関連書籍

 

Technology Books

Technology update books, technology news books, web designer books, web developer books, coding books books, creative coding books, Css books, Javascript books, programming books, Javascript developer books, technical knowledge books, work from home books, etc.


技术书籍

技术更新书籍,技术新闻书籍,网页设计师书籍,网页开发人员书籍,编码书籍书籍,创意编码书籍,Css书籍,Javascript书籍,编程书籍,Javascript开发人员书籍,技术知识书籍,在家工作书籍等。


Technologie-Bücher

Technologie-Update-Bücher, Technologie-News-Bücher, Web-Designer-Bücher, Web-Entwickler-Bücher, Coding-Bücher, kreative Coding-Bücher, Css-Bücher, Javascript-Bücher, Programmier-Bücher, Javascript-Entwickler-Bücher, technisches Wissen Bücher, Arbeit von zu Hause Bücher, etc.


技術関連書籍

技術アップデート本、技術ニュース本、ウェブデザイナー本、ウェブ開発者本、コーディング本、クリエイティブコーディング本、CSS本、Javascript本、プログラミング本、Javascript開発者本、技術知識本、在宅ワーク本、等々です。

 Packages and Builtin Functions

Packages and built-in functions
We discussed packages without really describing what they are, so let's look at packages and how they fit into the overall Python structure. As mentioned earlier, Python is object-oriented, which means that everything is an object, and you will understand this in practice, but there are some important built-in functions that are not objects, and they are worth mentioning here because they will be used throughout the book. These built-in types will be used throughout the book, so keep an eye out for them. We show some useful ones below, for a complete list, see

click here.

dir(): This function takes in an object and returns the _dir_() of that object giving us the attributes of the object.

>>> name = 'Rob'

>>> dir(name)

['__add__', '__class__', '__contains__', '__delattr__', '__dir__', '__doc__',

'__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__',

'__getnewargs__', '__gt__', '__hash__', '__init__', '__init_subclass__',

'__iter__', '__le__', '__len__', '__lt__', '__mod__', '__mul__', '__ne__',

'__new__', '__reduce__', '__reduce_ex__', '__repr__', '__rmod__',

'__rmul__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__',

'capitalize', 'casefold', 'center', 'count', 'encode', 'endswith',

'expandtabs', 'find', 'format', 'format_map', 'index', 'isalnum', 'isalpha',

'isascii', 'isdecimal', 'isdigit', 'isidentifier', 'islower', 'isnumeric', 'isprintable', 'isspace', 'istitle', 'isupper', 'join', 'ljust', 'lower',

'lstrip', 'maketrans', 'partition', 'replace', 'rfind', 'rindex', 'rjust',

'rpartition', 'rsplit', 'rstrip', 'split', 'splitlines', 'startswith',

'strip', 'swapcase', 'title', 'translate', 'upper', 'zfill']

  float(): Returns a floating point number from an integer of string

>>> x = '1'

>>> float(1)

1.0

  int(): Returns an integer from a float of string

>>> x = '1'

>>> int(1)

1

The Python Book, First Edition. Rob Mastrodomenico.

© 2022 John Wiley & Sons Ltd. Published 2022 by John Wiley & Sons Ltd.

3 Packages and Builtin Functions

  len(): Returns the length of an object

>>> name = 'Rob'

>>> len(name)

3

>>> x = [1, 2, 3, 4]

>>> len(x)

4

  list(): Creates a list from the argument given

>>> name = 'rob'

>>> list(name)

['r', 'o', 'b']

  max(): Gives the maximum value from the argument provided

>>> x = [1, 2, 3, 4]

>>> max(x)

4

>>> name = ['r', 'o', 'b']

>>> max(name)

'r'

  min(): Gives the minimum value from the argument provided

>>> x = [1, 2, 3, 4]

>>> min(x)

1

>>> name = ['r', 'o', 'b']

>>> min(name)

'b'

  print(): Prints the object to the text stream

>>> x = [1, 2, 3, 4]

>>> print(x) [1, 2, 3, 4]

  round(): Rounds the number to a specified precision

>>> y = 1.387668

>>> round(y,2)

1.39

  str(): Converts the object to type string

>>> y = 1.387668

>>> str(y) '1.387668'

3 Packages and Builtin Functions

  type(): Returns the type of an object

>>> y = 1.387668

>>> type(y)

<class 'float'>

  abs(): Returns the absolute value of a numeric value passed in

>>> z = -0.657

>>> abs(z)

0.657

  help(): Gives access to the Python help system >>> help(list)

Help on class list in module builtins:

class list(object)

| list(iterable=(), /)

|

| Built-in mutable sequence.

|

| If no argument is given, the constructor creates a new empty list.

| The argument must be an iterable if specified.

|

| Methods defined here:

|

| __add__(self, value, /) |     Return self+value.

|

| __contains__(self, key, /) |  Return key in self.

|

| __delitem__(self, key, /) |   Delete self[key].

|

| __eq__(self, value, /)

            |     Return self==value.

If you are not familiar with Python, the concepts used above are introduced in this book.


In addition to these built-in functions, Python comes with a number of packages that perform specific tasks and are imported into our code. These packages perform specific tasks and are imported into our code. python has several default packages, but there are also many third-party packages that we can use as well. In the Anaconda distribution, we get all the default packages, as well as the packages described earlier. In this book, we will examine both the default packages and the third-party packages. To demonstrate this, we will show you how to import a package. The package we're going to introduce is datetime, which is part of the standard Python library. This means that it comes with Python and was not developed by a third party. Now to import the datetime package, all you need to do is enter the following.

>>> import datetime

3 Packages and Builtin Functions

In doing this we now have access to everything within datetime and to see what datetime contains we can run the built in function dir which as we showed earlier gives us the attribute of the object.

>>> import datetime

>>> dir(datetime)

['MAXYEAR', 'MINYEAR', '__builtins__', '__cached__', '__doc__', '__file__',

'__loader__', '__name__', '__package__', '__spec__', 'date', 'datetime',

'datetime_CAPI', 'sys', 'time', 'timedelta', 'timezone', 'tzinfo']

Now if we want to see what these attributes are we use the dot syntax to access attributes of the object. So to see what MINYEAR and MAXYEAR are we can do so as follows.

>>> import datetime

>>> datetime.MAXYEAR

9999

>>> datetime.MINYEAR

1

Now we can import specific parts of a package by using the from syntax as demonstrate below.

>>> from datetime import date

So, this means importing a specific date property from the package datetime. This is the only aspect of datetime that we have access to. It's a good practice to import only what you need from the package. Now, every time we want to use date, we have to call date, which is easy in this case, but you can also give the import an alias, which reduces your code.

>>> from datetime import date as d

These are the basics of importing packages, and throughout this book we will import from a variety of packages and show how to use the same syntax to import our own code. In addition to the built-in functions, these are the key concepts that we will use extensively throughout this book.


No comments:

Post a Comment

Thank you for Contacting Us.

Post Top Ad