30. Understanding the Basics of Python Programming

Ace your homework & exams now with Quizwiz!

What is python byte level code compiled to?

.pyc

<string>.asalpha()

<string>.asalpha() Returns True if all characters in the string are in the alphabet

<string>.endswith()

<string>.endswith() Returns true if the string ends with the specified value

<string>.find()

<string>.find() Searches the string for a specified value and returns the position of where it was found

<string>.format()

<string>.format() Formats specified values in a string

<string>.index()

<string>.index() Searches the string for a specified value and returns the position of where it was found

<string>.isalnum()

<string>.isalnum() Returns True if all characters in the string are alphanumeric

<string>.replace()

<string>.replace() Returns a string where a specified value is replaced with a specified value

What are the two main ways to execute python code

Using the Python dynamic interpreter. Writing Python scripts

What is the command to concatenate strings?

+

Things to remember about creating python scripts:

-include shebang at beginning of script -define an entry point -code is -files end with .py -python scripts are executed as python [scriptname].py

What should you do for python readability?

-single line comments start with # -multiline comments need delimiter -group statements using indentation -use the python style guide (PEP8) for coding conventions

<string>.split()

<string>.split() Splits the string at the specified separator, and returns a list

<string>.startswith()

<string>.startswith() Returns true if the string starts with the specified value

<string>.upper() / .lower()

<string>.upper() / .lower() Returns True if all characters in the string are uppercase/lowercase

What are comparison operators?

==, !=, >, <, >=, <=

T/F: There is a strict scope for variables that are defined under the entry point conditional. Any variable that is defined under the entry point if block is a local variable.

False

T/F: python scripts must be compiled in order to run.

False.

What does the \n option do?

New line

Which version of Python is supported on NX-OS?

Python2

List some common python data types

Strings: Sequences of character data Numbers: Integers allowing for mathematical operation to be performed directly in code Lists: Container used to store multiple data at the same time Dictionaries: Uses key value pairs to match keys to their value Booleans: Values and operators used in code Files: Objects used by Python

What is a boolean?

a binary variable that represents true (1) or false (0)

What are logical operators?

and, or, not

What operations can be applied to booleans?

and, or, not

What function can you use on any object to see its available built-in methods

dir()

How do you write a float versus an integer?

float must have decimal point, integer must not

What are some important built in python helper tools?

help = returns the python built in documentation about the object dir = returns the attributes of object or module type = returns the type of an object

What are conditional statements?

if, elif, and else.

What are membership operators?

in, not in

What are identity operators?

is, is not

What is the difference between a global and local variable?

local defined as part of the script, global is defined first and then referenced in the definition

What type of language is Python?

object oriented

What is the command to open the Python shell in a Linux terminal or from the CLI of a Cisco Nexus?

python

What are the commands to create and open a file in command line?

touch creates, gedit=open

Describe a few string modifying commands

—replace modified the ":" in the MAC address to. "" startswith — Verified that the IP address begins with "10" format — Added the value "200" to the specified area indicated by{} —Createdplit a list from the values separated by the indicated. ""


Related study sets

Advanced Social Media & Analytics Midterm

View Set

LAND USE CONTROLS AND REGULATIONS TEST

View Set

TOPIC 7.8 Mass Atrocities After 1900

View Set