python


Python 3, receive a string as an argument without any return value


I'm learning Python and have been taking an online class. This class was very basic and I am know trying to continue my studies elsewhere. Stackoverflow.com has helped me a great deal. In the online course we didn't cover a lot about return statements, which I am now trying to learn. I would like to do something very basic, so I was thinking of creating a program that would receive a string as an argument without having any return value. I want the user to type a word that will be shown with characters or symbols between every letter.
Example
User types in the word Python.
The word will be shown as =P=y=t=h=o=n= or -P-y-t-h-o-n- or maybe with * between every letter.
Is this an easy task? Can someone help me how to go about doing this?
Thank you.
Joel
If you want to do it yourself, you can go through your string like this:
my_string = "Python"
for letter in my_string:
# do something with the letter
print(letter)
This will print each letter in your word. What you want to do is having a new string with your desired character. You probably know you can concatenate (append) two strings in this way :
str1 = "hello"
str2 = "world"
str3 = str1 + str2
print(str3) #helloworld
So to do what you'd like to do, you can see each letter as a substring of your main string, and your desired character (for example *) as another string, and build a result string in that way.
inputString = "Python"
result = ""
myChar = "*"
for letter in inputString:
# build your result
build = build + letter
print(build)
This will just copy inputString into result, though I think you'll have understood how to use it in order to add your custom chars between the letters.
Yes python makes this sort of string manipulation very easy (some other languages... not so much). Look up the standard join function in the python docs.
def fancy_print(s, join_char='-'):
# split string into a list of characters
letters = list(s)
# create joined string
output = join_char + join_char.join(letters) + join_char
# show it
print(output)
then
>>> fancy_print("PYTHON")
-P-Y-T-H-O-N-
>>> fancy_print("PYTHON", "*")
*P*Y*T*H*O*N*

Related Links

Execute python script on remote server from another script
Passing a variable between two methods in Python?
What is the best way to add custom methods into generated protoc classes for Python?
Retain edit data for one form when submitting a second
Associating string representations with a Python Enum that uses integer values
python3 for win and cygwin - line endings in buffer
How invert the result used the method sort
Adjusting weights based on share prices for a investment portfolio using pandas
Python split data and create variables/list of content (variable name + data)
Overwrite Not Working
Selenium: how to select text in CSS?
How to maintain dictionary element order in JSON dump in Python
How does adding a (500x5000) and (5000x1) matrix result in a (500x5000) matrix?
Merging arrays of varying size in Python
How would you Export a file with data in a table form in python?
CDF in Python not displaying correctly

Categories

HOME
app-inventor
payment-gateway
wsdl
bower
qpython3
visualization
extract
computer-vision
rfc
specflow
checksum
histogrammar
google-spreadsheet-api
eval
slim-3
ipfs
unity2d
game-maker-studio-1.4
uiscrollview
dlib
activesync
jacoco
multiple-monitors
ida
anychart
google-api-java-client
styles
multicore
shippo
prediction
piwik
jquery-waypoints
csh
hanami
spring-data-neo4j
i3
pygooglechart
devforce
exponential
oracle-xml-db
qtablewidget
openpgp
geomesa
vsts-package-management
rhel.net
sonarqube-scan
ntfs-mft
restful-url
jupyter-console
constants
stress-testing
apiary
fqdn
appstore-approval
scd
info
heroku-postgres
pdfkit
gulp-typescript
atlassian-crowd
hspec
tomee
cron-task
freetype2
kendo-combobox
inet
git-rebase
jta
hyperthreading
optionbutton
wikitext
zuora
on-duplicate-key
gray-code
hg-git
alpha-transparency
winrt-httpclient
loop-invariant
driver-signing
dllexport
ruboto
stagefright
entity-framework-4.1
zend-lucene
xml-libxml
marmalade-edk
qsqltablemodel
objective-c-protocol
userid
hobo
datamember
gtk2hs
ihttphandler
gethashcode
symbol-server
surefire
graniteds
asp.net-mvc-controller
associativity

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App