Last active
August 29, 2015 13:58
-
-
Save hungneox/9997750 to your computer and use it in GitHub Desktop.
Python string function vs PHP string function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$parrot = "Norwegian Blue"; | |
echo strlen($parrot); | |
echo strtolower($parrot); | |
echo strtoupper($parrot); | |
$pi = 3.14 | |
echo $pi; | |
if(is_string($pi)): | |
echo "string"; | |
else: | |
echo "not a string"; | |
endif; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
parrot = "Norwegian Blue" | |
print len(parrot) | |
print parrot.lower() | |
print parrot.upper() | |
pi = 3.14 | |
print str(pi) #in Python you need to convert number to string in order to print it out | |
original = raw_input("Enter a word:") | |
## the function isalpha() which returns False since the string contains non-letter characters. | |
if len(original) > 0 and original.isalpha(): | |
print original | |
else: | |
print "empty" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
print "Please input somethings:" | |
user_input = gets.chomp | |
temp = user_input.to_i | |
if temp.is_a?(String) | |
print "string" | |
else | |
print "is not a string" | |
end | |
if user_input.empty? | |
print "Please enter a non empty string:" | |
user_input = gets.chomp | |
end | |
user_input.downcase! | |
if user_input.include? "s" | |
user_input.gsub!(/s/,"th") | |
puts "#{user_input}" | |
else | |
print user_input | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment