Lesson2: String Operations, Writing Scripts
Lesson2: String Operations, Writing Scripts
Fundamentals of Text Processing for Linguists Na-Rae Han
Objectives
Writing and executing Python scripts
Learn Python basic syntax
Variable assignments: = vs. += Equality comparison: == String operations Boolean operators: and, or, not
1/15/2014
2
Interactive programming vs. scripts
We have been programming INTERACTIVELY through IDLE
shell.
IDLE interprets and
responds to each line
of code you type in
You have to retype the code next time
We will now try writing and running a stand-alone Python SCRIPT.
x = 'a'+'b'
print x
... ...
Python script file
1/15/2014
executed
Your IDLE shell
3
Python script in IDLE editor mode
1. Open up a new window (Ctrl+n). 2. Python editor window opens up. Type in: print "Hello, world!!" 3. Save the script as "hello.py".
Don't forget to include ".py" extension!
4. Run the script by selecting "Run" > "Run Module" or pressing F5. 5. Success! The command executes in the IDLE shell window.
1/15/2014
4
String operations
String: A single piece of text, composed of a sequence of letters.
Operations on string objects:
print
statement. prints string
len()
returns integer
+, +=
returns string
.endswith(), .startswith() returns True/False
in
returns True/False
.upper(), .lower()
returns string
.replace()
returns string
.split()
splits a string into a list, returns it
1/15/2014
5
................
................
In order to avoid copyright disputes, this page is only a partial summary.
To fulfill the demand for quickly locating and searching documents.
It is intelligent file search solution for home and business.
Related download
- programming principles in python csci 503
- introduction to python programming course notes
- basic python programming for loops and reading files
- how python works
- lesson2 string operations writing scripts
- introduction to python
- python input output and
- a guide to f string formatting in python
- introduction to computers programming input and output
- stanford university jay whang and zach maurer python review
Related searches
- meditation scripts for summer
- cross selling scripts for insurance
- scripts for selling insurance
- scripts for cross selling
- phone scripts for selling insurance
- insurance sales scripts examples
- life insurance scripts pdf
- insurance sales scripts samples
- insurance sales scripts that work
- insurance scripts for telemarketing
- express scripts covered drug list
- sales scripts for bank tellers